GD2 グラフィックス ライブラリに基づいて PHP で画像サムネイルを生成するためのコード共有_PHP チュートリアル
GD2グラフィックスライブラリに基づいてPHPを使用して画像サムネイルを生成するためのコード共有
この記事では、GD2グラフィックスライブラリに基づいてPHPを使用して画像サムネイルを生成するためのコード共有を主に紹介し、実装コードと使用方法を直接示します。必要なもの 友達が参考にしてください
PHP を使用して画像サムネイルを生成するには、PHP サーバーに GD2 グラフィックス ライブラリがインストールされていることを確認してください。画像サムネイルを生成するクラスを使用します。
1.使用方法
1 2
|
$resizeimage = new assignimage("画像ソースファイルアドレス", "200", "100", "0","サムネイルアドレス"); //上記の文を使用してサムネイルを生成するだけです。ソース ファイルとサムネイルのアドレスは同じにすることができ、200 と 100 はそれぞれ幅と高さを表します
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
//次のクラスを使用して画像のサムネイルを生成します。
クラスサイズ変更画像 { //写真の種類 var $type; //実際の幅 var $width; //実際の身長 var $height; //幅を変更しました var $resize_width; //変更後の身長 var $resize_height; //画像をトリミングするかどうか var $cut; //ソース画像 var $srcimg; //ターゲット画像アドレス var $dstimg; //一時的に作成された画像 var $im;
関数 Resizeimage($img, $wid, $hei,$c,$dstpath) { $this->srcimg = $img; $this->resize_width = $wid; $this->resize_height = $hei; $this->カット = $c; //写真の種類
$this->type = strto lower(substr(strrchr($this->srcimg,"."),1));
//画像を初期化します $this->initi_img(); //ターゲット画像アドレス $this -> dst_img($dstpath); //-- $this->width = 画像x($this->im); $this->高さ = imagey($this->im); //画像を生成する $this->newimg(); ImageDestroy ($this->im); } 関数 newimg() { //変更された画像の割合 $resize_ratio = ($this->resize_width)/($this->resize_height); //実際の画像の比率 $ratio = ($this->幅)/($this->高さ); 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), $これ->高さ); ImageJpeg ($newimg,$this->dstimg); } if($ratio //宽度优先 { $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- >身長); ImageJpeg ($newimg,$this->dstimg); } if($ratio { $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- >身長); 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;
//echo $this->dstimg; } } |

絶対セッションのタイムアウトはセッションの作成時に開始され、アイドルセッションタイムアウトはユーザーの操作なしに開始されます。絶対セッションタイムアウトは、金融アプリケーションなど、セッションライフサイクルの厳格な制御が必要なシナリオに適しています。アイドルセッションタイムアウトは、ソーシャルメディアなど、ユーザーが長い間セッションをアクティブに保つことを望んでいるアプリケーションに適しています。

サーバーセッションの障害は、手順に従って解決できます。1。セッションが正しく設定されていることを確認するために、サーバーの構成を確認します。 2.クライアントCookieを確認し、ブラウザがそれをサポートしていることを確認し、正しく送信します。 3. Redisなどのセッションストレージサービスを確認して、それらが正常に動作していることを確認します。 4.アプリケーションコードを確認して、正しいセッションロジックを確認します。これらの手順を通じて、会話の問題を効果的に診断および修復し、ユーザーエクスペリエンスを改善することができます。

session_start()iscrucialinphpformangingusersions.1)itInitiateSanewsessionifnoneExists、2)resumesanexistingsession、および3)SetSessionCookieforcontinuityAcrossRequests、ApplicationslicationSliviseSlikeUserauthicationAnticatent。

HTTPonlyフラグを設定することは、XSS攻撃を効果的に防止し、ユーザーセッション情報を保護することができるため、セッションCookieにとって重要です。具体的には、1)HTTPONLYフラグは、JavaScriptがCookieにアクセスするのを防ぎます。2)Flagは、PHPとFlaskのSetCookiesとMake_Responseを介して設定できます。

phpsessionssolvetheprobrof of maintainsea crossmultiplehttprequestsbyStoringdataontaonsociatingitiTauniquesessionid.1)それらは、通常はヨーロッパの側面、および一般的には、測定されている

phpssionscanStorestrings、numbers、arrays、andobjects.1.strings:textdatalikeusernames.2.numbers:integersorfloatsforcounters.3.arrays:listslikeshoppingcarts.4.objects:complextructuresthataresialized。

tostartaphpsession、outsession_start()atthescript'sbeginning.1)placeitbe foreanyouttosetthesscookie.2)usesionsionsionsionserdatalikelogintatussorshoppingcarts.3)再生セッションインドストップレベントフィックスアタック

セッション再生とは、新しいセッションIDを生成し、セッション固定攻撃の場合にユーザーが機密操作を実行するときに古いIDを無効にすることを指します。実装の手順には次のものが含まれます。1。感度操作を検出、2。新しいセッションIDを生成する、3。古いセッションIDを破壊し、4。ユーザー側のセッション情報を更新します。


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

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

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

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

WebStorm Mac版
便利なJavaScript開発ツール

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

ホットトピック









