ホームページ バックエンド開発 PHPチュートリアル 画像処理ソフト photoshop 2 つの強力な php 画像処理クラス 1

画像処理ソフト photoshop 2 つの強力な php 画像処理クラス 1

Jul 29, 2016 am 08:40 AM

コードをコピーします コードは次のとおりです:


/**
* 画像のインデントとウォーターマークの追加を完了するために使用される基本的な画像処理
* ウォーターマーク画像がターゲット画像サイズを超える場合、ウォーターマーク画像はターゲット画像に自動的に適応して縮小されます
* ウォーターマーク画像は、ターゲット画像とマージするように設定できます背景
*
* Copyright(c) 2005 by ustb99. All Rights Reserved
*
* 著者に連絡するには、{@link mailto:ustb80@163.com} までご連絡ください
*
* @author by happens
* @version $ ID:thumb.class.php,v 1.9 2006/09/30 09:31:56 zengjian Exp $
* @パッケージ システム
*/
/**
* ThumbHandler
* @access public
*/
/*
使用方法:
自動トリミング:
プログラムは、画像のサイズを指定し、目的のサイズに応じて省略します
$t->setSrcImg("img/test.jpg");//この文はOKです
$t- >setDstImg ("tmp/new_test.jpg");
$t->createImg(60,60);
手動トリミング:
プログラムは指定された位置に従ってソース画像から画像を取得します
$t- >setSrcImg(" img/test.jpg");
$t->setCutType(2);//手動カットを示します
$t->setSrcCutPosition(100, 100);//ソース画像
$t->setRectangleCut(300, 200); // トリミングサイズ
$t->setDstImg("tmp/new_test.jpg");
$t->createImg(300,200); /
class ThumbHandler
{
var $dst_img; // 対象ファイル
var $h_src; // 新しい画像ハンドル
var $h_mask; // ウォーターマーク ハンドル
var $img_create_quality = 100 ; // 画像生成品質
var $img_display_quality = 80; // 画像表示品質、デフォルトは 75
var $src_w = 0; // 元の画像幅
var $src_h; = 0; // 元の画像の高さ
var $dst_w = 0; // 新しい画像の合計の高さ
var $fill_w; // 塗りつぶされたグラフィックの幅
var $fill_h; // 塗りつぶされたグラフィックの高さ
var $ copy_w;// コピーされたグラフィックの幅
var $copy_h;// コピーされたグラフィックの高さ
var $src_x = 0;// 元の画像の描画開始の横座標
var $src_y = 0;//元の画像描画の開始座標
var $start_x; // 新しい画像の描画の開始座標
var $start_y; // 新しい画像の描画の開始座標
var $mask_word; // var $mask_img; // ウォーターマーク画像
var $mask_pos_x = 0; // ウォーターマークの横座標
var $mask_offset_x = 5; // ウォーターマークの横方向のオフセット
/ ウォーターマークの垂直オフセット
var $font_h; // ウォーターマークのフォントの高さ
var $mask_h; // ウォーターマークの高さ
var $mask_font_color = " "; // ウォーターマークの文字色
var $mask_font = 2; // ウォーターマークのフォント
var $font_size; // サイズ
var $mask_position = 0; // ウォーターマークの位置
var $mask_img_pct = 50; // 画像の結合度,値が大きいほど結合処理が低くなります
var $mask_txt_pct = 50;// テキストの結合度、値が小さいほど結合処理が低くなります
var $img_border_size = 0;// 画像の枠線サイズ
var $img_border_color; // 画像の枠線の色
var $_flip_x=0;/ / 水平反転数
var $_flip_y=0; // 垂直反転数
var $cut_type=0; // カットタイプ
var $img_type; type
// ファイルタイプの定義、出力画像を示します Function
var $all_type = array(
"jpg" => array("output"=>"imagejpeg"),
"gif" => array( "output"=>"imagegif")、
" png" => array("output"=>"imagepng")、
"wbmp" => array("output"=>"image2wbmp") ,
"jpeg" =>array("output" =>"imagejpeg"));
/**
* コンストラクター
*/
function ThumbHandler()
{
$this->mask_font_color = "#ffffff" ;
$this->font_size = 12;
/**
* 画像の幅を取得します
*/
function getImgWidth($src)
return imagex($src); }
/**
* 画像の高さを取得します
*/
function getImgHeight ($src)
{
return imagey($src);
}
/**
* 画像生成パスを設定します
*
* @param string $src_img 画像生成パス
*/
function setSrcImg($src_img, $img_type=null)
{
if(!file_exists($src_img))
{
die("画像が存在しません");
}
if(!emptyempty($img_type))
{
$this->img_type = $img_type;
}
else
{
$this->img_type = $this->_getImgType($src_img);
}
$this->_checkValid($this->img_type)
// file_get_contents 関数が必要ですPHP バージョン >4.3.0
$src = '';
if(function_exists("file_get_contents"))
{
$src = file_get_contents($src_img);
else
{
$handle = fopen ($src_img, "r");
while (!feof ($handle) )
{
$src .= fgets($fd, 4096);
}
fclose ($handle)
if(emptyempty($src))
{
die("画像ソースが空です"
}
$this->h_src = @ImageCreateFromString($src);
$this->src_w = $this->getImgWidth($this-> h_src);
$this->src_h = $this->getImgHeight($this->h_src);
/**
* 画像生成パスを設定します
*
* @param string $dst_img 画像生成パス
*/
function setDstImg($dst_img)
{
$arr =explode('/',$dst_img);
$last = array_pop($arr);
$path = implode('/',$arr);
$this->_mkdirs($path);
$this->dst_img = $dst_img;
}
/**
* 画像の表示品質を設定します
*
* @param string $nquality
*/
function setImgDisplayQuality($n)
{
$this->img_display_quality = (int)$n;
}
/**
* 画像生成の品質を設定します
*
* @param string $nquality
*/
function setImgCreateQuality($n)
{
$this->img_create_quality = (int)$n;
}
/**
* テキスト透かしを設定します
*
* @param string $word 透かしテキスト
* @param integer $font 透かしフォント
* @param string $color 透かしフォントの色
*/
function setMaskWord($word)
{
$this->mask_word .= $word;
}
/**
* フォントの色を設定します
*
* @param string $color フォントの色
*/
function setMaskFontColor($color="#ffffff")
{
$this->mask_font_color = $color;
}
/**
* 透かしフォントを設定します
*
* @param string|integer $font font
*/
function setMaskFont($f
{
if(!is_numeric($font) && !file_exists($font))
{
die("字体文件無し");
}
$this->font = $font;
}
/**
* テキストのフォント サイズを設定します。TrueType フォントにのみ有効です
*/
function setMaskFontSize($size = "12")
{
$this->font_size = $size;
/**
* 画像の透かしを設定します
*
* @param string $img 透かし画像のソース
*/
function setMaskImg($img)
{
$this->mask_img = $img;
/**
* ウォーターマークの水平オフセットを設定します
*
* @param integer $x 水平オフセット
*/
function setMaskOffsetX($x)
{
$ this->mask_offset_x = (int)$x;
/**
* ウォーターマークの垂直オフセットを設定します
*
* @param integer $y 垂直オフセット
*/
function setMaskOffsetY($y)
{
$this->mask_offset_y = (int)$y;
/ **
* ウォーターマークの位置を指定します
*
* @param integer $position 位置、1: 左上、2: 左下、3: 右上、0/4: 右下
*/
function setMaskPosition($position=0)
{
$this->mask_position = (int)$position;
}
/**
* 画像の結合度を設定します
*
* @param integer $n 結合の度合い
*/
function setMaskImgPct($n)
{
$this->mask_img_pct = (int)$n;
/**
* テキストの結合度を設定します
*
* @param integer $n 結合度
*/
function setMaskTxtPct($n)
{
$this->mask_txt_pct = (int)$n;
}
/**
* サムネイルの境界線を設定します
*
* @param (種類) (パラメータ名) (説明)
*/
function setDstImgBorder($size=1, $color="#000000")
{
$this->img_border_size = (int)$size; img_border_color = $color;
/**
* 水平方向に反転します
*/
関数flipH()
{
$this->_flip_x++;
/**
* 垂直方向に反転します
*/
関数flipV()
$this->_flip_y++;
}
/**
* カットタイプを設定します
*
* @param (タイプ) (パラメータ名) (説明)
*/
function setCutType($type)
{
$this->cut_type = (int)$type;
}
/**
* 画像クリッピングを設定します
*
* @param integer $width 長方形クリッピング
*/
function setRectangleCut($width, $height)
{
$this->fill_w = (int)$width;
$this->fill_h = (int)$height;
}
/**
* ソース画像を切り出す開始座標点を設定します
*
* @param (種類) (パラメータ名) (説明)
*/
function setSrcCutPosition($x, $y)
{
$this->src_x = (int)$x;
$this->src_y = (int)$y;
}
/**
* 画像を作成、メイン関数
* @param integer $a 2 番目のパラメータが欠落している場合、このパラメータはパーセンテージとして使用されます。
* それ以外の場合は幅の値として使用されます
* @param integer $b 後の画像の高さスケーリング
*/
function createImg($a, $b=null)
{
$num = func_num_args();
if(1 == $num)
{
$r = (int)$a;
if($r {
die("图片缩放比不得小}
$this->img_scale = $r;
$this->_setNewImgSize($r);
}
if(2 == $num)
{
$w = (int)$a;
$h = (int)$b;
if(0 == $w)
{
die("目标宽度は0でない");
}
if(0 == $h)
{
die("目标高さを0にすることはできません");
}
$this->_setNewImgSize($w, $h);
}
if($this->_flip_x%2!=0)
{
$this->_flipH($this->h_src);
}
if($this->_flip_y%2!=0)
{
$this->_flipV($this->h_src);
}
$this->_createMask();
$this->_output();
// 释放
if(imagedestroy($this->h_src) && imagedestroy($this->h_dst))
{
Return true;
}
else
{
false を返します。
}
}
/**
* 透かしを生成するには、透かしテキストと透かし画像を生成する 2 つのメソッドが呼び出されます
*/
function _createMask()
{
if($this->mask_word)
{
// 获取字体情報
$this->_setFontInfo();
if($this->_isFull())
{
die("水印文字过大");
}
else
{
$this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
$white = ImageColorAllocate($this->h_dst,255,255,255);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// 塗りつぶされた背景色
$this->_drawBorder();
imagecopyresampled( $this->h_dst, $this->h_src,
$this->start_x, $this->start_y,
$this->src_x, $this->src_y,
$this ->fill_w、$this->fill_h、
$this->copy_w、$this->copy_h);
$this->_createMaskWord($this->h_dst);
}
}
if($this->mask_img)
{
$this->_loadMaskImg();//加ダウンロード時,取得宽高
if($this->_isFull())
{
/ / 将水印生成在原図上再コピー
$this->_createMaskImg($this->h_src);
$this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
$white = ImageColorAllocate($this->h_dst,255,255,255);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// 塗りつぶされた背景色
$this->_drawBorder();
imagecopyresampled( $this->h_dst, $this->h_src,
$this->start_x, $this->start_y,
$this->src_x, $this->src_y,
$this ->fill_w、$this->start_y、
$this->copy_w、$this->copy_h);
}
else
{
// 创建新しい画像并贝
$this->h_dst = imagecreatetruecolor($this->dst_w, $this->dst_h);
$white = ImageColorAllocate($this->h_dst,255,255,255);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// 塗りつぶされた背景色
$this->_drawBorder();
imagecopyresampled( $this->h_dst, $this->h_src,
$this->start_x, $this->start_y,
$this->src_x, $this->src_y,
$this ->fill_w、$this->fill_h、
$this->copy_w、$this->copy_h);
$this->_createMaskImg($this->h_dst);
}
}
if(emptyempty($this->mask_word) && emptyempty($this->mask_img))
{
$this->h_dst = imagecreatetruecolor($this->dst_w, $this-> ;dst_h);
$white = ImageColorAllocate($this->h_dst,255,255,255);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$white);// 塗りつぶされた背景色
$this->_drawBorder();
imagecopyresampled( $this->h_dst, $this->h_src,
$this->start_x, $this->start_y,
$this->src_x, $this->src_y,
$this ->fill_w、$this->fill_h、
$this->copy_w、$this->copy_h);
}
}
/**
* 境界線を描画します
*/
function _drawBorder()
{
if(!emptyempty($this->img_border_size))
{
$c = $this->_parseColor($this- >img_border_color);
$color = ImageColorAllocate($this->h_src,$c[0], $c[1], $c[2]);
imagefilledrectangle($this->h_dst,0,0,$this->dst_w,$this->dst_h,$color);// 塗りつぶされた背景色
}
}
/**
* 透かしテキストを生成します
*/
function _createMaskWord($src)
{
$this->_countMaskPos();
$this->_checkMaskValid();
$c = $this->_parseColor($this->mask_font_color);
$color = imagecolorallocatealpha($src, $c[0], $c[1], $c[2], $this->mask_txt_pct);
if(is_numeric($this->font))
{
imagestring($src,
$this->font,
$this->mask_pos_x, $this->mask_pos_y,
$this->>マスクワード、
$color);
}
else
{
imagettftext($src,
$this->font_size, 0,
$this->mask_pos_x, $this->mask_pos_y,
$color,
$this->font,
$this->mask_word);
}
}
/**
* 透かし画像を生成します
*/
function _createMaskImg($src)
{
$this->_countMaskPos();
$this->_checkMaskValid();
imagecopymerge($src,
$this->h_mask,
$this->mask_pos_x ,$this->mask_pos_y,
0, 0,
$this->mask_w, $this->mask_h,
$this->mask_img_pct);
imagedestroy($this->h_mask);
}
/**
* 透かし画像をロードします
*/
function _loadMaskImg()
{
$mask_type = $this->_getImgType($this->mask_img);
$this->_checkValid($mask_type);
// file_get_contents関数数要求phpバージョン本>4.3.0
$src = '';
if(function_exists("file_get_contents"))
{
$src = file_get_contents($this->mask_img);
}
else
{
$handle = fopen ($this->mask_img, "r");
while (!feof ($handle))
{
$src .= fgets($fd, 4096);
}
fclose ($handle);
}
if(emptyempty($this->mask_img))
{
die("水印图片のため空");
}
$this->h_mask = ImageCreateFromString($src);
$this->mask_w = $this->getImgWidth($this->h_mask);
$this->mask_h = $this->getImgHeight($this->h_mask);
}
/**
* 画像出力
*/
function _output()
{
$img_type = $this->img_type;
$func_name = $this->all_type[$img_type]['output'];
if(function_exists($func_name))
{
// 判断浏览器,若是IE就不送头
if(isset($_SERVER['HTTP_USER_AGENT']))
{
$ua = strtoupper($_SERVER[' HTTP_USER_AGENT']);
if(!preg_match('/^.*MSIE.*)$/i',$ua))
{
header("Content-type:$img_type");
}
}
$func_name($this->h_dst, $this->dst_img, $this->img_display_quality);
}
else
{
false を返します。
}
}
/**
* 色を分析する
*
* @param string $color 16 進数の色
*/
function _parseColor($color)
{
$arr = array();
for($ii=1; $ii{
$arr[] = hexdec(substr($color,$ii,2));
$ii++;
}
$arr を返します。
}
/**
* 位置座標を計算します
*/
function _countMaskPos()
{
if($this->_isFull())
{
switch($this->mask_position)
{
ケース 1:
/ / 左上
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
休憩;
ケース 2:
// 左下
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
休憩;
ケース 3:
// 右上
$this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
休憩;
ケース 4:
// 右下
$this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
$this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
休憩;
デフォルト:
// 默认水印を右下に放ち、オフセット指定画像素
$this->mask_pos_x = $this->src_w - $this->mask_w - $this->mask_offset_x;
$this->mask_pos_y = $this->src_h - $this->mask_h - $this->mask_offset_y;
休憩;
}
}
else
{
switch($this->mask_position)
{
case 1:
// 左上
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
休憩;
ケース 2:
// 左下
$this->mask_pos_x = $this->mask_offset_x + $this->img_border_size;
$this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
休憩;
ケース 3:
// 右上
$this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this->img_border_size;
$this->mask_pos_y = $this->mask_offset_y + $this->img_border_size;
休憩;
ケース 4:
// 右下
$this->mask_pos_x = $this->dst_w - $this->gt;mask_w - $this->mask_offset_x - $this->gt;img_border_size;
$this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
休憩;
デフォルト:
//默认水印を右下に放ち、偏移指定像素
$this->mask_pos_x = $this->dst_w - $this->mask_w - $this->mask_offset_x - $this- >img_border_size;
$this->mask_pos_y = $this->dst_h - $this->mask_h - $this->mask_offset_y - $this->img_border_size;
休憩;
}
}
}
/**
* フォント情報を設定します
*/
function _setFontInfo()
{
if(is_numeric($this->font))
{
$this->font_w = imagefontwidth($this- >フォント);
$this->font_h = imagefontheight($this->font);
// 计算水ボイス体所占宽高
$word_length = strlen($this->mask_word);
$this->mask_w = $this->font_w*$word_length;
$this->mask_h = $this->font_h;
}
else
{
$arr = imagettfbbox ($this->font_size,0, $this->font,$this->mask_word);
$this->mask_w = abs($arr[0] - $arr[2]);
$this->mask_h = abs($arr[7] - $arr[1]);
}
}
/**
* 新しい画像サイズを設定します
*
* @param integer $img_w ターゲット幅
* @param integer $img_h ターゲット高さ
*/
function _setNewImgSize($img_w, $img_h=null)
{
$num = func_num_args();
if(1 == $num)
{
$this->img_scale = $img_w;// 宽度作比
$this->fill_w =round($this->src_w * $this->img_scale / 100) - $this->img_border_size*2;
$this->fill_h =round($this->src_h * $this->img_scale / 100) - $this->img_border_size*2;
// ソース文件起始坐标
$this->src_x = 0;
$this->src_y = 0;
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_h;
// 目标尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
}
if(2 == $num)
{
$fill_w = (int)$img_w - $this->img_border_size*2;
$fill_h = (int)$img_h - $this->img_border_size*2;
if($fill_w < 0 || $fill_h < 0)
{
die("图片边框过大,既超过了图片的宽度");
}
$rate_w = $this->src_w/$fill_w;
$rate_h = $this->src_h/$fill_h;
switch($this->cut_type)
{
case 0:
// 如果原图大缩略图、生缩小、否不缩小
if($rate_w < 1 && $rate_h < 1)
{
$this->fill_w = (int)$this->src_w;
$this->fill_h = (int)$this->src_h;
}
else
{
if($rate_w >= $rate_h)
{
$this->fill_w = (int)$fill_w;
$this->fill_h =round($this->src_h/$rate_w);
}
else
{
$this->fill_w =round($this->src_w/$rate_h);
$this->fill_h = (int)$fill_h;
}
}
$this->src_x = 0;
$this->src_y = 0;
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_h;
// 目标尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
休憩;
// 自動裁切
case 1:
// 如果图片是缩小剪切才进実行操作
if($rate_w >= 1 && $rate_h >=1)
{
if($this->src_w > $this->src_h)
{
$src_x =round($this->src_w-$this->src_h)/2;
$this->setSrcCutPosition($src_x, 0);
$this->setRectangleCut($fill_h, $fill_h);
$this->copy_w = $this->src_h;
$this->copy_h = $this->src_h;
}
elseif($this->src_w < $this->src_h)
{
$src_y =round($this->src_h-$this->src_w)/2;
$this->setSrcCutPosition(0, $src_y);
$this->setRectangleCut($fill_w, $fill_h);
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_w;
}
else
{
$this->setSrcCutPosition(0, 0);
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_w;
$this->setRectangleCut($fill_w, $fill_h);
}
}
else
{
$this->setSrcCutPosition(0, 0);
$this->setRectangleCut($this->src_w, $this->src_h);
$this->copy_w = $this->src_w;
$this->copy_h = $this->src_h;
}
// 目标尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
休憩;
// 手工裁切
case 2:
$this->copy_w = $this->fill_w;
$this->copy_h = $this->fill_h;
// 目标尺寸
$this->dst_w = $this->fill_w + $this->img_border_size*2;
$this->dst_h = $this->fill_h + $this->img_border_size*2;
休憩;
デフォルト:
ブレイク;
}
}
// 目标文件起始坐标
$this->start_x = $this->img_border_size;
$this->start_y = $this->img_border_size;
}
/**
* ウォーターマーク画像が生成された画像の幅と高さより大きいかどうかを確認してください
*/
function _isFull()
{
Return ( $this->mask_w + $this->mask_offset_x > $this->fill_w
|| $this->マスク_h + $this->mask_offset_y > $this->fill_h)
?true:false;
}
/**
* ウォーターマーク画像が元の画像を超えていないか確認してください
*/
function _checkMaskValid()
{
if( $this->mask_w + $this->mask_offset_x > $this->src_w
|| $this->マスク_h + $this->mask_offset_y > $this->src_h)
{
die("水印图片尺寸大在原图,请缩小水印图");
}
}
/**
* 画像タイプを取得します
*
* @param string $file_path ファイルパス
*/
function _getImgType($file_path)
{
$type_list = array("1"=>​​"gif","2"=>"jpg","3"=>> "png","4"=>"swf","5" =>"psd","6"=>"bmp","15"=>"wbmp");
if(file_exists($file_path))
{
$img_info = @getimagesize ($file_path);
if(isset($type_list[$img_info[2]]))
{
Return $type_list[$img_info[2]];
}
}
else
{
die("文件が存在しません、文件类型を取得できません!");
}
}
/**
* 画像タイプが有効かどうかを確認し、array_key_exists 関数を呼び出します。この関数には
* 4.1.0 以降の PHP バージョンが必要です
*
* @param string $img_type ファイル タイプ
*/
function _checkValid($img_type)
{
if(!array_key_exists($img_type, $this->all_type))
{
Return false;
}
}
/**
* 指定されたパスに従ってディレクトリを生成します
*
* @param string $path path
*/
function _mkdirs($path)
{
$adir =explode('/',$path);
$dirlist = '';
$rootdir = array_shift($adir);
if(($rootdir!='.'||$rootdir!='..')&&!file_exists($rootdir))
{
@mkdir($rootdir);
}
foreach($adir as $key=>$val)
{
if($val!='.'&&$val!='..')
{
$dirlist .= "/".$ヴァル;
$dirpath = $rootdir.$dirlist;
if(!file_exists($dirpath))
{
@mkdir($dirpath);
@chmod($dirpath,0777);
}
}
}
}
/**
* 垂直反転
*
* @param string $src 画像ソース
*/
function _flipV($src)
{
$src_x = $this->getImgWidth($src);
$src_y = $this->getImgHeight($src);
$new_im = imagecreatetruecolor($src_x, $src_y);
for ($y = 0; $y {
imagecopy($new_im, $src, 0, $src_y - $y - 1, 0, $y, $src_x, 1);
}
$this->h_src = $new_im;
}
/**
* 水平方向に反転
*
* @param string $src 画像ソース
*/
function _flipH($src)
{
$src_x = $this->getImgWidth($src);
$src_y = $this->getImgHeight($src);
$new_im = imagecreatetruecolor($src_x, $src_y);
for ($x = 0; $x {
imagecopy($new_im, $src, $src_x - $x - 1, 0, $x, 0, 1, $src_y);
}
$this->h_src = $new_im;
}
}
使用例:
< ?php
require_once('lib/thumb.class.php');
$t->setSrcImg("img/test.jpg"); $t->setDstImg("tmp/new_test.jpg");
$t->setMaskImg("img/test.gif");
$t-> setMaskImgPct(80);
$t->setDstImgBorder(4,"#dddddd");
$t->createImg(300,200);
require_once ( 'lib/thumb.class.php');
$t = new ThumbHandler();
$t->setSrcImg("img/test.jpg"); ( "test");
$t->setDstImgBorder(10,"#dddddd");
$t->createImg(50);
equire_once( 'lib/thumb.class.php');
$t = new ThumbHandler()// 基本的な使い方
$t->setSrcImg("img/test.jpg"); setMaskWord( "test");
//固定の幅と高さを指定します
require_once('lib/thumb.class.php'); $t = new ThumbHandler();
$t->setSrcImg("img/test.jpg");
$t->setMaskWord( "test" );
//固定の幅と高さを指定します
$t; = new ThumbHandler( );
$t->setSrcImg("img/test.jpg");
// フォントファイルのアドレスを指定
$t->setMaskFont("c:/winnt/fonts/arial.ttf) ");
$ t->setMaskFontSize(20);
$t->setMaskFontColor("#ffff00");
$t->setMaskWord("test3333333");
$t->setDstImgBorder(99) ,"#dddddd" );
$t->createImg(50);
$t = new ThumbHandler();
$t->setSrcImg("img/test.jpg");
$t->setMaskOffsetX(55);
$t->setMaskPosition(1);
//$t ->setMaskPosition(2);
//$t->setMaskPosition(4); ");
$ t->setMaskWord("test");
//固定の幅と高さを指定
$t->createImg(50);
?>
require_once('lib/ sum.class.php' );
$t = new ThumbHandler();
$t->setSrcImg("img/test.jpg"); simyou.ttf");
$t->setMaskFontSize(20);
$t->setMaskFontColor("#ffffff");
$t->setMaskTxtPct(20);
$t->setDstImgBorder( 10,"#dddddd" );
$text = "中国語";
$t->setMaskWord($str); t->setMaskWord( "test");
//固定の幅と高さを指定します
$t->createImg(50);
上記では、画像処理ソフトウェア photoshop と 2 つの強力な PHP 画像処理カテゴリ 1 を紹介し、画像処理ソフトウェア photoshop の内容を含めて、PHP チュートリアルに興味のある友人に役立つことを願っています。


このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター

SublimeText3 中国語版

SublimeText3 中国語版

中国語版、とても使いやすい

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

JSON Web Tokens(JWT)とPHP APIでのユースケースを説明してください。 JSON Web Tokens(JWT)とPHP APIでのユースケースを説明してください。 Apr 05, 2025 am 12:04 AM

JWTは、JSONに基づくオープン標準であり、主にアイデンティティ認証と情報交換のために、当事者間で情報を安全に送信するために使用されます。 1。JWTは、ヘッダー、ペイロード、署名の3つの部分で構成されています。 2。JWTの実用的な原則には、JWTの生成、JWTの検証、ペイロードの解析という3つのステップが含まれます。 3. PHPでの認証にJWTを使用する場合、JWTを生成および検証でき、ユーザーの役割と許可情報を高度な使用に含めることができます。 4.一般的なエラーには、署名検証障害、トークンの有効期限、およびペイロードが大きくなります。デバッグスキルには、デバッグツールの使用とロギングが含まれます。 5.パフォーマンスの最適化とベストプラクティスには、適切な署名アルゴリズムの使用、有効期間を合理的に設定することが含まれます。

確固たる原則と、それらがPHP開発にどのように適用されるかを説明してください。 確固たる原則と、それらがPHP開発にどのように適用されるかを説明してください。 Apr 03, 2025 am 12:04 AM

PHP開発における固体原理の適用には、次のものが含まれます。1。単一責任原則(SRP):各クラスは1つの機能のみを担当します。 2。オープンおよびクローズ原理(OCP):変更は、変更ではなく拡張によって達成されます。 3。Lischの代替原則(LSP):サブクラスは、プログラムの精度に影響を与えることなく、基本クラスを置き換えることができます。 4。インターフェイス分離原理(ISP):依存関係や未使用の方法を避けるために、細粒インターフェイスを使用します。 5。依存関係の反転原理(DIP):高レベルのモジュールと低レベルのモジュールは抽象化に依存し、依存関係噴射を通じて実装されます。

PHPにおける後期静的結合の概念を説明します。 PHPにおける後期静的結合の概念を説明します。 Mar 21, 2025 pm 01:33 PM

記事では、PHP 5.3で導入されたPHPの後期静的結合(LSB)について説明し、より柔軟な継承を求める静的メソッドコールのランタイム解像度を可能にします。 LSBの実用的なアプリケーションと潜在的なパフォーマ

システムの再起動後にUnixSocketの権限を自動的に設定する方法は? システムの再起動後にUnixSocketの権限を自動的に設定する方法は? Mar 31, 2025 pm 11:54 PM

システムが再起動した後、UnixSocketの権限を自動的に設定する方法。システムが再起動するたびに、UnixSocketの許可を変更するために次のコマンドを実行する必要があります:sudo ...

PHPのCurlライブラリを使用してJSONデータを含むPOSTリクエストを送信する方法は? PHPのCurlライブラリを使用してJSONデータを含むPOSTリクエストを送信する方法は? Apr 01, 2025 pm 03:12 PM

PHP開発でPHPのCurlライブラリを使用してJSONデータを送信すると、外部APIと対話する必要があることがよくあります。一般的な方法の1つは、Curlライブラリを使用して投稿を送信することです。

フレームワークセキュリティ機能:脆弱性から保護します。 フレームワークセキュリティ機能:脆弱性から保護します。 Mar 28, 2025 pm 05:11 PM

記事では、入力検証、認証、定期的な更新など、脆弱性から保護するためのフレームワークの重要なセキュリティ機能について説明します。

フレームワークのカスタマイズ/拡張:カスタム機能を追加する方法。 フレームワークのカスタマイズ/拡張:カスタム機能を追加する方法。 Mar 28, 2025 pm 05:12 PM

この記事では、フレームワークにカスタム機能を追加し、アーキテクチャの理解、拡張ポイントの識別、統合とデバッグのベストプラクティスに焦点を当てています。

See all articles