<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## intervention/image使用 ### 不依賴與其他擴展包 #### 參考 - 官網 http://image.intervention.io/api/backup - PHP圖像處理組件:Intervention/image https://www.helloweba.net/php/545.html - Intervention/image 圖片處理 https://www.cnblogs.com/jxl1996/p/10255742.html #### 前置條件 該組件需要滿足以下條件才可以正常運行: * PHP >= 5.4 * 需要支持Fileinfo擴展 * GD庫 > 2.0 或者 Imagick擴展 >= 6.5.7 #### 安裝 使用 composer 安裝: ~~~ composer require intervention/image ~~~ #### 使用 在使用 Intervention Image 的時候, 你只需要給 ImageManager 傳一個數組參數就可以完成 GD 或 Imagick 庫之間的互相切換。 ~~~ // 引入 composer autoload require 'vendor/autoload.php'; // 導入 Intervention Image Manager Class use Intervention\Image\ImageManager; // 通過指定 driver 來創建一個 image manager 實例 $manager = new ImageManager(array('driver' => 'imagick')); // 最后創建 image 實例 $image = $manager->make('public/foo.jpg')->resize(300, 200); ~~~ 另外你也可以使用 ImageManager 的靜態版本, 如下所示: ~~~ // 引入 composer autoload require 'vendor/autoload.php'; // 導入 Intervention Image Manager Class use Intervention\Image\ImageManagerStatic as Image; // 通過指定 driver 來創建一個 image manager 實例 (默認使用 gd) Image::configure(array('driver' => 'imagick')); // 最后創建 image 實例 $image = Image::make('public/foo.jpg')->resize(300, 200); ~~~ #### 調整尺寸 當上傳的圖片尺寸不合適時,可以將圖片重新調整尺寸。 1.調整圖片為固定尺寸300x200像素: ~~~ $img = Image::make('public/foo.jpg') $img->resize(300, 200); ~~~ 僅調整圖片寬度為300像素: ~~~ $img->resize(300, null); ~~~ 僅調整圖片高度為200像素: ~~~ $img->resize(null, 200); ~~~ 調整圖片寬度為300像素,高度根據寬度等比例縮放: ~~~ $img->resize(300, null, function ($constraint) { $constraint->aspectRatio(); }); ~~~ 調整圖片高度為200像素,高度根據高度等比例縮放: ~~~ $img->resize(null, 200, function ($constraint) { $constraint->aspectRatio(); }); ~~~ #### 裁剪圖片 使用方法`crop(int $width, int $height, [int $x, int $y])`可以將圖片裁剪成合適的尺寸。 ~~~ $img = Image::make('public/foo.jpg'); $img->crop(100, 100, 25, 25); ~~~ 以上代碼將圖片從坐標x:25,y:25開始裁剪成100x100像素大小的圖片。 #### 圖片水印 使用方法:`insert(mixed $source, [string $position, [integer $x, integer $y]])`可以給圖片添加水印圖片,方法中第一個參數是水印圖片,第二個參數是水印的位置,支持9個位置,最后兩個參數是水印的相對$position參數的位移。 要想給圖片加個水印圖標,可以參照以下代碼: ~~~ // 修改指定圖片的大小 $img = Image::make('images/avatar.jpg')->resize(200, 200); // 插入水印, 水印位置在原圖片的右下角, 距離下邊距 10 像素, 距離右邊距 15 像素 $img->insert('images/watermark.png', 'bottom-right', 15, 10); // 將處理后的圖片重新保存到其他路徑 $img->save('images/new_avatar.jpg'); /* 上面的邏輯可以使用鏈式表達式 */ $img = Image::make('images/avatar.jpg')->resize(200, 200)->insert('images/new_avatar.jpg', 'bottom-right', 15, 10); ~~~ 這時你查看新生成的圖片new\_avatar.jpg的右下角會有水印圖標。 #### 圖片緩存 要想緩存圖片,先得安裝另外一個組件:imagecache。 ~~~ composer require intervention/imagecache ~~~ 我們使用方法`cache( Closure $callback, [int $lifetime, [bool $returnObj]] )`,可以實現圖片緩存功能。第2個參數`$lifetime`是緩存時間,默認為5,單位分鐘。 ~~~ $img = Image::cache(function($image) { $image->make('public/foo.jpg')->resize(300, 200)->greyscale(); }, 10, true); ~~~ 以上代碼將圖片foo.jpg重置大小為300x200,并且變成灰色,保存在緩沖區,緩存過期時間為10分鐘。 #### 圖片根據URL參數動態處理大小 當你上傳一張圖片后需要生成多種尺寸的圖片,比如常見的頭像尺寸就有多個尺寸以滿足不同應用展示。那么我們的解決辦法有:1.上傳時就生成裁剪好多種相應的尺寸,2.根據請求帶參數的URL來生成不同尺寸的圖片。方法1有局限性,必須先設定尺寸,方法2比較靠譜,根據傳遞的參數,生成所需尺寸的圖片,而且結合圖片緩存功能,讓生成的圖片緩存起來,那么在緩存期限內,多次請求同一個URL是不會重復生成圖片的。以下是個簡單的示例: ~~~ <?php require 'vendor/autoload.php'; use Intervention\Image\ImageManagerStatic as Image; $s = isset($_GET['s']) ? $_GET['s'] : 'medium'; switch ($s) { case 'small': //60x60 px $imgName = 'public/60x60.jpg'; $width = 60; $height = 60; break; case 'medium': //150x150 $imgName = 'public/150x150.jpg'; $width = 150; $height = 150; break; case 'large': //300x300 $imgName = 'public/300x300.jpg'; $width = 300; $height = 300; break; default: $imgName = 'public/150x150.jpg'; $width = 150; $height = 150; break; } $img = Image::cache(function($image) use ($imgName, $width, $height) { $image->make('public/foo.jpg')->resize($width, $height)->save($imgName); }, 600); //緩存:600min echo $imgName; ~~~ 根據傳遞的參數s,生成不同尺寸的圖片,并且緩存600分鐘。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看