PHP で強力な imagick を使用すると、結合されたサムネイルを簡単に生成できます
project: blogtarget: use-imagick-to-composite-images-thumbnail.mddate: 2016-02-19status: publishtags: - php - imagick - thumbnailcategories: - php
ここで説明する imagick
は、PHP での ImageMagick
の拡張機能です。 pecl
を使用したインストールは簡単でシンプルです。コマンドは 1 つだけです:
sudo pecl install imagick
(拡張機能のインストール後、extension=imagick.so
を php.ini に追加し、必ず または apache
サービス) php-fpm
拡張機能を使用しています。 imagick
この要件は、次のようなサムネイルを生成することです:
- 画像が 1 枚ある場合は、この画像のサムネイルを直接生成します。
- 画像が 2 枚ある場合は、1 つをオンにします。左側と右側に 1 つずつ、
- 3 つの写真がある場合、2 つの写真の左側が均等に分配され、1 つは右側を占めます。フィールド グリッドと同じようにスペースが均等に分散されている場合、
- にさらに多くの写真がある場合は、最初の 4 枚の写真のみが撮影され、サムネイルは次のように生成されます。フィールドグリッド方式。
- かなりの数のルールがありますが、それほど複雑ではありません。
試してみましょう:
namespace \clarence\thumbnail;class Thumbnail extends \Imagick{ /** * @param array $images * @param int $width * @param int $height * @return static * @throws ThumbnailException */ public static function createFromImages($images, $width, $height){ if (empty($images)){ throw new ThumbnailException("No images!"); } $thumbnail = new static(); $thumbnail->newImage($width, $height, 'white', 'jpg'); $thumbnail->compositeImages($images); return $thumbnail; } public function compositeImages($images){ $imagesKeys = array_keys($images); $compositeConfig = $this->calcCompositeImagesPosAndSize($images); foreach ($compositeConfig as $index => $cfg){ $imgKey = $imagesKeys[$index]; $img = new \Imagick($images[$imgKey]); $img = $this->makeCompositeThumbnail($img, $cfg); $this->compositeImage($img, self::COMPOSITE_OVER, $cfg['to']['x'], $cfg['to']['y']); } } protected function makeCompositeThumbnail(\Imagick $img, $cfg){ $img->cropThumbnailImage($cfg['size']['width'], $cfg['size']['height']); return $img; } protected function calcCompositeImagesPosAndSize($images){ $width = $this->getImageWidth(); $height = $this->getImageHeight(); switch(count($images)){ case 0: throw new ThumbnailException("No images!"); case 1: // | 0 | return [ 0 => [ 'to' => [ 'x' => 0, 'y' => 0 ], 'size' => [ 'width' => $width, 'height' => $height, ] ] ]; case 2: // | 0 | 1 | return [ 0 => [ 'to' => [ 'x' => 0, 'y' => 0 ], 'size' => [ 'width' => $width / 2, 'height' => $height, ] ], 1 => [ 'to' => [ 'x' => $width / 2, 'y' => 0], 'size' => [ 'width' => $width / 2, 'height' => $height, ] ] ]; case 3: // | 0 | 1 | // | 2 | | return [ 0 => [ 'to' => [ 'x' => 0, 'y' => 0 ], 'size' => [ 'width' => $width / 2, 'height' => $height / 2, ] ], 1 => [ 'to' => [ 'x' => $width / 2, 'y' => 0], 'size' => [ 'width' => $width / 2, 'height' => $height, ] ], 2 => [ 'to' => [ 'x' => 0, 'y' => $height / 2 ], 'size' => [ 'width' => $width / 2, 'height' => $height / 2, ] ], ]; default: // >= 4: // | 0 | 1 | // | 2 | 3 | return [ 0 => [ 'to' => [ 'x' => 0, 'y' => 0 ], 'size' => [ 'width' => $width / 2, 'height' => $height / 2, ] ], 1 => [ 'to' => [ 'x' => $width / 2, 'y' => 0], 'size' => [ 'width' => $width / 2, 'height' => $height / 2, ] ], 2 => [ 'to' => [ 'x' => 0, 'y' => $height / 2 ], 'size' => [ 'width' => $width / 2, 'height' => $height / 2, ] ], 3 => [ 'to' => [ 'x' => $width / 2, 'y' => $height / 2], 'size' => [ 'width' => $width / 2, 'height' => $height / 2, ] ], ]; } }}
効果はすぐに出ました:
$thumbnail = \clarence\thumbnail\Thumbnail::createFromImages($srcImages, 240, 320);$thumbnail->writeImage($outputDir."/example.jpg");
いいね~

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。ユーザー側のセッション情報を更新します。

PHPセッションは、アプリケーションのパフォーマンスに大きな影響を与えます。最適化方法には以下が含まれます。1。データベースを使用してセッションデータを保存して応答速度を向上させます。 2。セッションデータの使用を削減し、必要な情報のみを保存します。 3.非ブロッキングセッションプロセッサを使用して、同時実行機能を改善します。 4.セッションの有効期限を調整して、ユーザーエクスペリエンスとサーバーの負担のバランスを取ります。 5.永続的なセッションを使用して、データの読み取り時間と書き込み時間を減らします。

phpsesionsareserver-side、whilecookiesareclient-side.1)Sessionsionsionsoredataontheserver、aremoresecure.2)cookiesstoredataontheclient、cookiestoresecure、andlimitedinsizeisize.sesionsionsionivationivationivationivationivationivationivationivate

phpidentifiesauser'ssessionsingsinssessionCookiesIds.1)whensession_start()iscalled、phpgeneratesauniquesidstoredsored incoookienadphpsessidontheuser'sbrowser.2)thisidallowsphptortorieSessiondatadata fromthata

PHPセッションのセキュリティは、次の測定を通じて達成できます。1。session_regenerate_id()を使用して、ユーザーがログインまたは重要な操作である場合にセッションIDを再生します。 2. HTTPSプロトコルを介して送信セッションIDを暗号化します。 3。Session_Save_Path()を使用して、セッションデータを保存し、権限を正しく設定するためのSecure Directoryを指定します。

phpsessionFilesToredInthededirectoryspecifiedBysession.save_path、通常/tmponunix-likesystemsorc:\ windows \ temponwindows.tocustomizethis:1)uesession_save_path()tosetaCustomdirectory、ensuringit'swritadistradistradistradistradistra


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

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

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

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

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

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

ホットトピック









