検索
ホームページphp教程php手册サムネイルを生成するための PHP クラス コード

サムネイルを生成するための PHP クラス コード

Jun 13, 2016 pm 12:26 PM
20phpコード著者関数日付生成する親切


/**
* 機能: サムネイルの生成
* 作成者: phpox
* 日付: Thu May 17 09:57:05 CST 2007
*/

class CreatMiniature
{
//パブリック変数
var $srcFile=""; //オリジナルPicture
var $echoType; //出力画像タイプ、リンク -- ファイルとして保存されません。
var $im="" //一時変数
var $srcW =" "; //元の画像の幅
var $srcH="" //元の画像の高さ

//変数と初期化を設定します
関数 SetVar($srcFile,$echoType)
{
if (!file_exists($srcFile)){
echo 'ソース画像ファイルが存在しません!'
exit();
$this->srcFile =$srcFile;
$this->echoType=$echoType;

$info = "";
$data = GetImageSize($this->srcFile,$info); >switch ($ data[2])
{
ケース 1:
if(!function_exists("imagecreatefromgif")){
echo "GD ライブラリでは GIF 形式の画像を使用できません。Jpeg を使用してくださいまたは PNG 形式! return";
exit();
}
$this->im = ImageCreateFromGIF ( $this->srcFile);
break;
ケース 2:
if(!function_exists("imagecreatefromjpeg")){
echo "あなたの GD ライブラリは jpeg 形式の画像を使用できません。他の形式の画像を使用してください。戻り";
exit();
}
$this->im = ImageCreateFromJpeg($this ->srcFile);
break;
ケース 3:
$this->im = ImageCreateFromPNG($this->srcFile); this->srcW=ImageSX($this->im);
$this->srcH=ImageSY($this->im);
}

// 扭曲の生成型缩图
function Distortion($toFile,$toW,$toH​​)
{
$cImg=$this->CreatImage($this->im,$toW,$toH​​,0, 0,0,0,$this->srcW,$this->srcH);
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg); >}

// 比例配分の図を生成
function Prorate($toFile,$toW,$toH​​)
{
$toWH=$toW/$toH; >$srcWH=$this->srcW/$this->srcH;
if($toWH{
$ftoW=$toW=$ ftoW*($this->srcH/$this->srcW);
}
else
{
$ftoH=$toH*($ this->srcW/$this->srcH);
}
if($this->srcW>$toW||$this->srcH>$toH)
{
$cImg=$this->CreatImage($this->im,$ftoW,$ftoH,0,0,0,0,$this->srcW,$this->srcH); return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}
else
{
$cImg=$this->CreatImage($this->im,$this->srcW,$this->srcH,0,0, 0,0,$this->srcW,$this->srcH);
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}
}

// 最小裁剪後の缩图を生成
function Cut($toFile,$toW,$toH​​)
{
$toWH=$toW /$toH;
$srcWH=$this->srcW/$this->srcH;
if($toWH{
$ctoH=$toH;
$ctoW=$ctoH*($this->srcW/$this->srcH);
}
else
{
$ctoW=$toW;
$ctoH=$ctoW*($this->srcH/$this->srcW);
}
$allImg=$this->CreatImage($this->im,$ctoW,$ctoH,0,0,0,0,$this->srcW,$this->; srcH);
$cImg=$this->CreatImage($allImg,$toW,$toH​​,0,0,($ctoW-$toW)/2,($ctoH-$toH)/2,$toW,$へ);
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
ImageDestroy($allImg);
}

//背景充填の缩図を生成
function BackFill($toFile,$toW,$toH​​,$bk1=255,$bk2=255,$bk3=255)
{
$toWH=$toW/$toH;
$srcWH=$this->srcW/$this->srcH;
if($toWH{
$ftoW=$toW;
$ftoH=$ftoW*($this->srcH/$this->srcW);
}
else
{
$ftoH=$toH;
$ftoW=$ftoH*($this->srcW/$this->srcH);
}
if(function_exists("imagecreatetruecolor"))
{
@$cImg=ImageCreateTrueColor($toW,$toH​​);
if(!$cImg)
{
$cImg=ImageCreate($toW,$toH​​);
}
}
else
{
$cImg=ImageCreate($toW,$toH​​);
}
$backcolor = imagecolorallocate($cImg, $bk1, $bk2, $bk3); // 塗りつぶされた背景色
ImageFilledRectangle($cImg,0,0,$toW,$toH​​,$backcolor);
if($this->srcW>$toW||$this->srcH>$toH)
{
$proImg=$this->CreatImage($this->im, $ftoW,$ftoH,0,0,0,0,$this->srcW,$this->srcH);
if($ftoW{
ImageCopy($cImg,$proImg,($toW-$ftoW)/2,0,0,0,$ftoW,$ftoH);
}
else if($ftoH{
ImageCopy($cImg,$proImg,0,($toH-$ftoH)/2,0,0,$ftoW, $ftoH);
}
else
{
ImageCopy($cImg,$proImg,0,0,0,0,$ftoW,$ftoH);
}
}
else
{
ImageCopyMerge($cImg,$this->im,($toW-$ftoW)/2,($toH-$ftoH)/2 ,0,0,$ftoW,$ftoH,100);
}
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}


関数 CreatImage($img,$creatW,$creatH,$dstX,$dstY,$srcX,$srcY,$srcImgW,$srcImgH)
{
if(function_exists("imagecreatetruecolor"))
{
@$creatImg = ImageCreateTrueColor($creatW,$creatH);
if($creatImg)
ImageCopyResampled($creatImg,$img,$dstX,$dstY,$srcX,$srcY,$creatW,$creatH,$srcImgW,$srcImgH);
else
{
$creatImg=ImageCreate($creatW,$creatH);
ImageCopyResize($creatImg,$img,$dstX,$dstY,$srcX,$srcY,$creatW,$creatH,$srcImgW,$srcImgH);
}
}
else
{
$creatImg=ImageCreate($creatW,$creatH);
ImageCopyResize($creatImg,$img,$dstX,$dstY,$srcX,$srcY,$creatW,$creatH,$srcImgW,$srcImgH);
}
$creatImg を返す;
}

//画像を出力、リンク---出力のみ、文書は保存しない。file--文書として保存
function EchoImage($img,$to_File)
{
switch($this->echoType)
{
case "link":
if(function_exists('imagejpeg')) return ImageJpeg($img);
それ以外の場合は ImagePNG($img) を返します;
休憩;
case "file":
if(function_exists('imagejpeg')) return ImageJpeg($img,$to_File);
それ以外の場合は ImagePNG($img,$to_File) を返します;
休憩;
}
}
}
?>

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、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ヘンタイを無料で生成します。

ホットツール

AtomエディタMac版ダウンロード

AtomエディタMac版ダウンロード

最も人気のあるオープンソースエディター

メモ帳++7.3.1

メモ帳++7.3.1

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

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強力な PHP 統合開発環境

VSCode Windows 64 ビットのダウンロード

VSCode Windows 64 ビットのダウンロード

Microsoft によって発売された無料で強力な IDE エディター

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール