PHP を使用して画像のサムネイルを生成する_PHP チュートリアル
PHP は画像のサムネイルを生成します:
PHP を使用して画像サムネイルを生成するには、PHP サーバーに GD2 グラフィック ライブラリがインストールされていることを確認してください
クラスを使用して画像のサムネイルを生成します。以下のクラスのソースコードを参照してください。
このクラスメソッドを呼び出します:resizeimage = new assignimage("画像ソースファイルアドレス", "200", "100", "0","サムネイルアドレス");
//上記の文を使用してサムネイルを生成するだけです。ソースファイルとサムネイルのアドレスは同じにすることができ、200 と 100 はそれぞれ幅と高さを表します
//次のクラスを使用して画像のサムネイルを生成します。
クラスサイズ変更画像
{
//画像タイプ
var 型;
//実際の幅
var幅;
//実際の身長
変数の高さ;
//幅を変更しました
varsize_width;
//変更後の身長
varsize_height;
//画像をトリミングするかどうか
バーカット;
//ソース画像
var srcimg;
//対象画像アドレス
var dstimg;
//一時的に作成した画像
ヴァルイム;
関数resizeimage(img, wid, hei,c,dstpath)
{
this->srcimg = img;
this->resize_width = wid;
this->resize_height = hei;
this->cut = c;
//写真の種類
this->type = strto lower(substr(strrchr(this->srcimg,"."),1));
//画像を初期化する
this->initi_img();
//対象画像アドレス
これ -> dst_img(dstpath);
//--
this->width = imagex(this->im);
this->height = imagey(this->im);
//画像を生成する
this->newimg();
ImageDestroy (this->im);
}
関数newimg()
{
//変更された画像の割合
resize_ratio = (this->resize_width)/(this->resize_height);
//実際の画像の比率
比率 = (この->幅)/(この->高さ);
if((this->cut)=="1")
//画像をトリミング
{
if(ratio>=resize_ratio)
//優先度高
{
newimg = imagecreatetruecolor(this->resize_width,this->resize_height);
Imagecopyresampled(newimg, this->im, 0, 0, 0, 0, this->resize_width, this->resize_height, ((this->height)*resize_ratio), this->height);
ImageJpeg (newimg,this->dstimg);
}
if(比率
//幅を優先
{
newimg = imagecreatetruecolor(this->resize_width,this->resize_height);
imagecopyresampled(newimg, this->im, 0, 0, 0, 0, this->resize_width, this->resize_height, this->width, ((this->width)/resize_ratio));
ImageJpeg (newimg,this->dstimg);
}
}
その他
//トリミングなし
{
if(ratio>=resize_ratio)
{
newimg = imagecreatetruecolor(this->resize_width,(this->resize_width)/ratio);
imagecopyresampled(newimg, this->im, 0, 0, 0, 0, this->resize_width, (this->resize_width)/ratio, this->width, this->height);
ImageJpeg (newimg,this->dstimg);
}
if(比率
{
newimg = imagecreatetruecolor((this->resize_height)*ratio,this->resize_height);
imagecopyresampled(newimg, this->im, 0, 0, 0, 0, (this->resize_height)*ratio, this->resize_height, this->width, this->height);
ImageJpeg (newimg,this->dstimg);
}
}
}
//画像を初期化する
関数initi_img()
{
if(this->type=="jpg")
{
this->im = imagecreatefromjpeg(this->srcimg);
}
if(this->type=="gif")
{
this->im = imagecreatefromgif(this->srcimg);
}
if(this->type=="png")
{
this->im = imagecreatefrompng(this->srcimg);
}
}
//画像ターゲットアドレス
関数dst_img(dstpath)
{
full_length = strlen(this->srcimg);
type_length = strlen(this->type);
name_length = full_length-type_length;
name = substr(this->srcimg,0,name_length-1);
this->dstimg = dstpath;
//これをエコー>dstimg;
}
}
?>

ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

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

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

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

ホットトピック

PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

CakePHP でデータベースを操作するのは非常に簡単です。この章では、CRUD (作成、読み取り、更新、削除) 操作について理解します。

ファイルのアップロードを行うには、フォーム ヘルパーを使用します。ここではファイルアップロードの例を示します。

CakePHP は、PHP 用のオープンソース フレームワークです。これは、アプリケーションの開発、展開、保守をより簡単にすることを目的としています。 CakePHP は、強力かつ理解しやすい MVC のようなアーキテクチャに基づいています。モデル、ビュー、コントローラー

CakePHP へのログインは非常に簡単な作業です。使用する関数は 1 つだけです。 cronjob などのバックグラウンド プロセスのエラー、例外、ユーザー アクティビティ、ユーザーが実行したアクションをログに記録できます。 CakePHP でのデータのログ記録は簡単です。 log()関数が提供されています

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、
