/**
* 画像のインデントとウォーターマークの追加を完了するために使用される基本的な画像処理
* ウォーターマーク画像がターゲット画像サイズを超える場合、ウォーターマーク画像はターゲット画像に自動的に適応して縮小されます
* ウォーターマーク画像は、ターゲット画像とマージするように設定できます背景
*
* 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($font=2)
{
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;
$this->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 {
die("图片边框过大,既超过了图片的宽度");
}
$rate_w = $this->src_w/$fill_w;
$rate_h = $this->src_h/$fill_h;
switch($this->cut_type)
{
case 0:
// 如果原图大缩略图、生缩小、否不缩小
if($rate_w {
$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 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;
}
}
使用例:
require_once('lib/thumb.class.php');
$t->setSrcImg("img/test.jpg"); $t->setDstImg("tmp/new_test.jpg");
$t->setMaskImg("img/test.gif");
$t->setMaskPosition(1); 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);
http://www.bkjia.com/PHPjc/320199.html
www.bkjia.com
本当
http://www.bkjia.com/PHPjc/320199.html
技術記事
次のようにコードをコピーします: ?php /** * 画像のインデントとウォーターマークの追加を完了するために使用される基本的な画像処理* ウォーターマーク画像がターゲット画像サイズを超える場合、ウォーターマーク画像はターゲット画像に自動的に適応します...

PHPは、動的なWeb開発およびサーバー側のアプリケーションに使用されるサーバー側のスクリプト言語です。 1.PHPは、編集を必要とせず、迅速な発展に適した解釈言語です。 2。PHPコードはHTMLに組み込まれているため、Webページの開発が簡単になりました。 3。PHPプロセスサーバー側のロジック、HTML出力を生成し、ユーザーの相互作用とデータ処理をサポートします。 4。PHPは、データベースと対話し、プロセスフォームの送信、サーバー側のタスクを実行できます。

PHPは過去数十年にわたってネットワークを形成しており、Web開発において重要な役割を果たし続けます。 1)PHPは1994年に発信され、MySQLとのシームレスな統合により、開発者にとって最初の選択肢となっています。 2)コア関数には、動的なコンテンツの生成とデータベースとの統合が含まれ、ウェブサイトをリアルタイムで更新し、パーソナライズされた方法で表示できるようにします。 3)PHPの幅広いアプリケーションとエコシステムは、長期的な影響を促進していますが、バージョンの更新とセキュリティの課題にも直面しています。 4)PHP7のリリースなど、近年のパフォーマンスの改善により、現代の言語と競合できるようになりました。 5)将来的には、PHPはコンテナ化やマイクロサービスなどの新しい課題に対処する必要がありますが、その柔軟性とアクティブなコミュニティにより適応性があります。

PHPの中心的な利点には、学習の容易さ、強力なWeb開発サポート、豊富なライブラリとフレームワーク、高性能とスケーラビリティ、クロスプラットフォームの互換性、費用対効果が含まれます。 1)初心者に適した学習と使用が簡単。 2)Webサーバーとの適切な統合および複数のデータベースをサポートします。 3)Laravelなどの強力なフレームワークを持っています。 4)最適化を通じて高性能を達成できます。 5)複数のオペレーティングシステムをサポートします。 6)開発コストを削減するためのオープンソース。

PHPは死んでいません。 1)PHPコミュニティは、パフォーマンスとセキュリティの問題を積極的に解決し、PHP7.xはパフォーマンスを向上させます。 2)PHPは最新のWeb開発に適しており、大規模なWebサイトで広く使用されています。 3)PHPは学習しやすく、サーバーはうまく機能しますが、タイプシステムは静的言語ほど厳格ではありません。 4)PHPは、コンテンツ管理とeコマースの分野で依然として重要であり、エコシステムは進化し続けています。 5)OpcacheとAPCを介してパフォーマンスを最適化し、OOPと設計パターンを使用してコードの品質を向上させます。

PHPとPythonには独自の利点と短所があり、選択はプロジェクトの要件に依存します。 1)PHPは、Web開発に適しており、学習しやすく、豊富なコミュニティリソースですが、構文は十分に近代的ではなく、パフォーマンスとセキュリティに注意を払う必要があります。 2)Pythonは、簡潔な構文と学習が簡単なデータサイエンスと機械学習に適していますが、実行速度とメモリ管理にはボトルネックがあります。

PHPは動的なWebサイトを構築するために使用され、そのコア関数には次のものが含まれます。1。データベースに接続することにより、動的コンテンツを生成し、リアルタイムでWebページを生成します。 2。ユーザーのインタラクションを処理し、提出をフォームし、入力を確認し、操作に応答します。 3.セッションとユーザー認証を管理して、パーソナライズされたエクスペリエンスを提供します。 4.パフォーマンスを最適化し、ベストプラクティスに従って、ウェブサイトの効率とセキュリティを改善します。

PHPはMySQLIおよびPDO拡張機能を使用して、データベース操作とサーバー側のロジック処理で対話し、セッション管理などの関数を介してサーバー側のロジックを処理します。 1)MySQLIまたはPDOを使用してデータベースに接続し、SQLクエリを実行します。 2)セッション管理およびその他の機能を通じて、HTTPリクエストとユーザーステータスを処理します。 3)トランザクションを使用して、データベース操作の原子性を確保します。 4)SQLインジェクションを防ぎ、例外処理とデバッグの閉鎖接続を使用します。 5)インデックスとキャッシュを通じてパフォーマンスを最適化し、読みやすいコードを書き、エラー処理を実行します。

PHPで前処理ステートメントとPDOを使用すると、SQL注入攻撃を効果的に防ぐことができます。 1)PDOを使用してデータベースに接続し、エラーモードを設定します。 2)準備方法を使用して前処理ステートメントを作成し、プレースホルダーを使用してデータを渡し、メソッドを実行します。 3)結果のクエリを処理し、コードのセキュリティとパフォーマンスを確保します。


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

Dreamweaver Mac版
ビジュアル Web 開発ツール

EditPlus 中国語クラック版
サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター

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