PHP はさまざまなサイズのアプリ ロゴのバッチ生成を実装します。phpapp サイズ logo_PHP チュートリアル
PHPは、さまざまなサイズのアプリロゴ、phpappサイズのロゴのバッチ生成を実現します
PHP GDを使用すると、使いやすく、ワンクリックでさまざまなサイズにカットし、パッケージ化してダウンロードできます。アイコンを頻繁に変更する人は知っていると思いますが、アーティストから 1024 のロゴが提供され、それをフォトショップでさまざまなサイズに変換する必要があるため、このようなものを思いつきました。
コアコード
复制代码代码如下:
クラスイメージ{
/**
*出典画像
*
* @var 文字列|配列
*/
プライベート $source;
/**
*一時的な画像
*
* @var ファイル
*/
プライベート $image;
プライベート $ext;
/**
* エラー
*
* @var 配列
*/
プライベート $error;
/**
* 構築します
*
* @param 文字列|配列 $source
*/
パブリック関数 __construct($source = NULL) {
if($source != NULL) {
$this->source($source);
}
}
/**
*ソース画像を設定します
*
* @param 文字列|配列 $source
*/
パブリック関数ソース($source) {
if(!is_array($source)) {
$this->source["name"] = $source;
$this->source["tmp_name"] = $source;
$type = NULL;
$ext = strto lower(end(explode(".",$source)));
スイッチ($ext) {
ケース「jpg」 :
case "jpeg" : $type = "画像/jpeg";休憩;
case "gif" : $type = "image/gif";休憩;
case "png" : $type = "image/png";休憩;
}
$this->source["type"] = $type;
} その他 {
$this->source = $source;
}
$this->destination = $this->source["name"];
}
/**
*画像のサイズを変更します
*
* @param int $width
* @param int $height
*/
パブリック関数リサイズ($width = NULL,$height = NULL) {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"])) {
list($source_width,$source_height) = getimagesize($this->source["tmp_name"]);
if(($width == NULL) && ($height != NULL)) {
$width = ($source_width * $height) / $source_height;
}
if(($width != NULL) && ($height == NULL)) {
$height = ($source_height * $width) / $source_width;
}
if(($width == NULL) && ($height == NULL)) {
$width = $source_width;
$height = $source_height;
}
switch($this->source["type"]) {
case "image/jpeg" : $created = imagecreatefromjpeg($this->source["tmp_name"]);休憩;
case "image/gif" : $created = imagecreatefromgif($this->source["tmp_name"]); 休憩;
case "image/png" : $created = imagecreatefrompng($this->source["tmp_name"]); 休憩;
}
$this->image = imagecreatetruecolor($width,$height);
imagecopyresampled($this->image,$created,0,0,0,0,$width,$height,$source_width,$source_height);
}
}
/**
* 画像に透かしを追加します
*
* @param 文字列 $mark
* @param int $opac
* @param int $x_pos
* @param int $y_pos
*/
パブリック関数ウォーターマーク($mark,$opac,$x_pos,$y_pos) {
if(file_exists($mark) && ($this->image != "")) {
$ext = strto lower(end(explode(".",$mark)));
スイッチ($ext) {
ケース「jpg」 :
ケース "jpeg" : $watermark = imagecreatefromjpeg($mark);休憩;
case "gif" : $watermark = imagecreatefromgif($mark); 休憩;
case "png" : $watermark = imagecreatefrompng($mark); 休憩;
}
list($watermark_width,$watermark_height) = getimagesize($mark);
$source_width = 画像x($this->画像);
$source_height = imagey($this->image);
if($x_pos == "トップ") $pos = "t"; else $pos = "b";
if($y_pos == "左") $pos .= "l"; else $pos .= "r";
$dest_x = 0;
$dest_y = 0;
スイッチ($pos) {
case "tr" : $dest_x = $source_width - $watermark_width;休憩;
ケース "bl" : $dest_y = $source_height - $watermark_height;休憩;
case "br" : $dest_x = $source_width - $watermark_width; $dest_y = $source_height - $watermark_height;休憩;
}
imagecopymerge($this->image,$watermark,$dest_x,$dest_y,0,0,$watermark_width,$watermark_height,$opac);
}
}
/**
*画像をトリミングします
*
* @param int $x
* @param int $y
* @param int $width
* @param int $height
*/
パブリック関数 Crop($x,$y,$width,$height) {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"]) && ($width > 10) && ($height > 10)) {
switch($this->source["type"]) {
case "image/jpeg" : $created = imagecreatefromjpeg($this->source["tmp_name"]);休憩;
case "image/gif" : $created = imagecreatefromgif($this->source["tmp_name"]); 休憩;
case "image/png" : $created = imagecreatefrompng($this->source["tmp_name"]); 休憩;
}
$this->image = imagecreatetruecolor($width,$height);
imagecopy($this->image,$created,0,0,$x,$y,$width,$height);
}
}
/**
* 最終的なイメージファイルを作成します
*
* @param string $destination
* @param int $quality
*/
パブリック関数 create($destination,$quality = 100) {
if($this->image != "") {
$extension = substr($destination,-3,3);
スイッチ($extension) {
ケース「gif」:
imagegif($this->image,$destination,$quality);
休憩;
ケース「png」:
$quality = ceil($quality/10) - 1;
imagepng($this->image,$destination,$quality);
休憩;
デフォルト :
imagejpeg($this->image,$destination,$quality);
休憩;
}
}
}
/**
* 拡張機能が有効かどうかを確認してください
*
*/
パブリック関数 validate_extension() {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"])) {
$exts = array("image/jpeg", "image/pjpeg", "image/png", "image/x-png");
$ext = $this->source["type"];
$有効 = 0;
$this->ext = '.not_found';
if ($ext == $exts[0] || $ext == $exts[1]) {
$有効 = 1;
$this->ext = '.jpg';
}
// if ($ext == $exts[2]) {
// $valid = 1;
// $this->ext = '.gif';
// }
if ($ext == $exts[2] || $ext == $exts[3]) {
$有効 = 1;
$this->ext = '.png';
}
if($valid != 1) {
$this->error .= "拡張子";
}
} その他 {
$this->error .= "ソース";
}
}
/**
*サイズが正しいかどうかを確認してください
*
* @param int $max
*/
パブリック関数 validate_size($max) {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"])) {
$max = $max * 1024;
if($this->source["size"] >= $max) {
$this->error .= "サイズ";
}
} その他 {
$this->error .= "ソース";
}
}
/**
*寸法が正しいかどうかを確認してください
*
* @param int $limit_width
* @param int $limit_height
*/
パブリック関数 validate_dimension($limit_width,$limit_height) {
if(isset($this->source["tmp_name"]) && file_exists($this->source["tmp_name"])) {
list($source_width,$source_height) = getimagesize($this->source["tmp_name"]);
if(($source_width > $limit_width) || ($source_height > $limit_height)) {
$this->error .= "ディメンション";
}
} その他 {
$this->error .= "ソース";
}
}
/**
* 見つかったエラーを取得します
*
*/
パブリック関数 error() {
$error = array();
if(stristr($this->error,"source")) $error[] = "找不到達上传文件";
if(stristr($this->error,"dimension")) $error[] = "上传图片尺寸太大";
if(stristr($this->error,"extension")) $error[] = "不符合要求的格式";
if(stristr($this->error,"size")) $error[] = "图片文件太大";
$error を返します;
}
パブリック関数 error_string() {
$error = "";
if(stristr($this->error,"source")) $error .= "找不到達上传文件 / ";
if(stristr($this->error,"dimension")) $error .= "上传图片尺寸太大 / ";
if(stristr($this->error,"extension")) $error .= "不符合要求的格式 / ";
If(stristr($this->error,"size")) $error .= "画像ファイルが大きすぎます / ";
If(エレギ(" / $", $error)) {
$error = substr($error, 0, -3);
}
return $error;
}
パブリック関数 ext() {
戻る $this->ext;
}
}
この記事で説明した内容は以上です。皆さんに気に入っていただければ幸いです。

ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の 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 にアップグレードする方法について説明します。

あなたが経験豊富な PHP 開発者であれば、すでにそこにいて、すでにそれを行っていると感じているかもしれません。あなたは、運用を達成するために、かなりの数のアプリケーションを開発し、数百万行のコードをデバッグし、大量のスクリプトを微調整してきました。

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

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

文字列は、文字、数字、シンボルを含む一連の文字です。このチュートリアルでは、さまざまな方法を使用してPHPの特定の文字列内の母音の数を計算する方法を学びます。英語の母音は、a、e、i、o、u、そしてそれらは大文字または小文字である可能性があります。 母音とは何ですか? 母音は、特定の発音を表すアルファベットのある文字です。大文字と小文字など、英語には5つの母音があります。 a、e、i、o、u 例1 入力:string = "tutorialspoint" 出力:6 説明する 文字列「TutorialSpoint」の母音は、u、o、i、a、o、iです。合計で6元があります

このチュートリアルでは、PHPを使用してXMLドキュメントを効率的に処理する方法を示しています。 XML(拡張可能なマークアップ言語)は、人間の読みやすさとマシン解析の両方に合わせて設計された多用途のテキストベースのマークアップ言語です。一般的にデータストレージに使用されます

静的結合(静的::) PHPで後期静的結合(LSB)を実装し、クラスを定義するのではなく、静的コンテキストで呼び出しクラスを参照できるようにします。 1)解析プロセスは実行時に実行されます。2)継承関係のコールクラスを検索します。3)パフォーマンスオーバーヘッドをもたらす可能性があります。

PHPの魔法の方法は何ですか? PHPの魔法の方法には次のものが含まれます。1。\ _ \ _コンストラクト、オブジェクトの初期化に使用されます。 2。\ _ \ _リソースのクリーンアップに使用される破壊。 3。\ _ \ _呼び出し、存在しないメソッド呼び出しを処理します。 4。\ _ \ _ get、dynamic属性アクセスを実装します。 5。\ _ \ _セット、動的属性設定を実装します。これらの方法は、特定の状況で自動的に呼び出され、コードの柔軟性と効率を向上させます。
