<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Imagecow基于 PHP 的圖像處理庫

          聯(lián)合創(chuàng)作 · 2023-09-29 23:08

          Imagecow 是一個(gè)用于操作和生成響應(yīng)式圖像的 PHP 庫。

          • PHP >= 5.5
          • 使用 GD2 或 Imagick 庫
          • 非常簡單、快速且易于使用。

          簡單使用示例:

          use Imagecow\Image;
          
          Image::fromFile('my-image.gif')
              ->autoRotate()
              ->resizeCrop(300, 400, 'center', 'middle')
              ->format('png')
              ->save('converted-image.png')
              ->show();
          

          如何使用

          安裝

          這個(gè)包可以通過 Composer 安裝和自動(dòng)加載。

          $ composer require imagecow/imagecow
          

          創(chuàng)建一個(gè) Imagecow\Image 實(shí)例:

          use Imagecow\Image;
          
          //Using Imagick:
          $image = Image::fromFile('my-image.jpg', Image::LIB_IMAGICK);
          
          //Detect the available library automatically
          //(in order of preference: Imagick, Gd)
          $image = Image::fromFile('my-image.jpg');
          
          //Create an instance from a string
          $image = Image::fromString(file_get_contents('my-image.jpg'));
          

          調(diào)整大小

          Image::resize($width, $height = 0, $cover = false)

          調(diào)整圖像大小保持縱橫比。

          注意:如果新圖片比原圖片大,圖片不會(huì)調(diào)整大小

          • $width:圖像的最大寬度??梢允褂冒俜直然驍?shù)字(像素)
          • $height:圖像的最大高度。可以使用百分比或數(shù)字
          • $cover:如果是true,則新尺寸將涵蓋寬度和高度值。這就像 css 的image-size: cover.
          //Assuming the original image is 1000x500
          
          $image->resize(200);                    // change to 200x100
          $image->resize(0, 200);                 // change to 400x200
          $image->resize(200, 300);               // change to 200x100
          $image->resize(2000, 2000);             // keeps 1000x500
          

          裁剪

          Image::crop($width, $height, $x = 'center', $y = 'middle')

          裁剪圖像:

          • $width:裁剪圖像的寬度,它可以是數(shù)字(像素)或百分比
          • $height:裁剪圖像的高度,它可以是數(shù)字(像素)或百分比
          • $x:裁剪的水平偏移量。它可以是一個(gè)數(shù)字(對(duì)于像素)或百分比。您還可以使用關(guān)鍵字left,centerright
          • $y:裁剪的垂直偏移。與 $x 一樣,它可以是數(shù)字或百分比。您還可以使用關(guān)鍵字top,middlebottom
          $image->crop(200, 300);                 // crops to 200x300px
          $image->crop(200, 300, 'left', 'top');  // crops to 200x300px from left and top
          $image->crop(200, 300, 20, '50%');      // crops to 200x300px from 20px left and 50% top
          $image->crop('50%', '50%');             // crops to half size
          
          瀏覽 35
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  调教女M屁股撅虐调教 | A片免费观看网站 | 丁香五月婷婷综合 | 亚洲操B在线看 | 亚洲中文综合 |