亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

PHP擴展之圖像處理3——ImageMagick使用及相關類和方法

瀏覽:5日期:2022-09-15 17:25:30
Example #1 在 Imagick 中創建縮略圖

<?phpheader(’Content-type: image/jpeg’);$image = new Imagick(’image.jpg’);// If 0 is provided as a width or height parameter,// aspect ratio is maintained$image->thumbnailImage(100, 0);echo $image;?>

Example #2 Make a thumbnail of all JPG files in a directory

<?php$images = new Imagick(glob(’images/*.JPG’));foreach($images as $image) {// Providing 0 forces thumbnailImage to maintain aspect ratio$image->thumbnailImage(1024,0);}$images->writeImages();?>

Example #3 Creating a reflection of an image

<?php/* Read the image */$im = new Imagick('test.png');/* Thumbnail the image */$im->thumbnailImage(200, null);/* Create a border for the image */$im->borderImage(new ImagickPixel('white'), 5, 5);/* Clone the image and flip it */$reflection = $im->clone();$reflection->flipImage();/* Create gradient. It will be overlayed on the reflection */$gradient = new Imagick();/* Gradient needs to be large enough for the image and the borders */$gradient->newPseudoImage($reflection->getImageWidth() + 10, $reflection->getImageHeight() + 10, 'gradient:transparent-black');/* Composite the gradient on the reflection */$reflection->compositeImage($gradient, imagick::COMPOSITE_OVER, 0, 0);/* Add some opacity. Requires ImageMagick 6.2.9 or later */$reflection->setImageOpacity( 0.3 );/* Create an empty canvas */$canvas = new Imagick();/* Canvas needs to be large enough to hold the both images */$width = $im->getImageWidth() + 40;$height = ($im->getImageHeight() * 2) + 30;$canvas->newImage($width, $height, new ImagickPixel('black'));$canvas->setImageFormat('png');/* Composite the original image and the reflection on the canvas */$canvas->compositeImage($im, imagick::COMPOSITE_OVER, 20, 10);$canvas->compositeImage($reflection, imagick::COMPOSITE_OVER, 20, $im->getImageHeight() + 10);/* Output the image*/header('Content-Type: image/png');echo $canvas;?>

以上例程的輸出類似于:

PHP擴展之圖像處理3——ImageMagick使用及相關類和方法

Example #4 Filling text with gradient

<?php/* Create a new imagick object */$im = new Imagick();/* Create new image. This will be used as fill pattern */$im->newPseudoImage(50, 50, 'gradient:red-black');/* Create imagickdraw object */$draw = new ImagickDraw();/* Start a new pattern called 'gradient' */$draw->pushPattern(’gradient’, 0, 0, 50, 50);/* Composite the gradient on the pattern */$draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im);/* Close the pattern */$draw->popPattern();/* Use the pattern called 'gradient' as the fill */$draw->setFillPatternURL(’#gradient’);/* Set font size to 52 */$draw->setFontSize(52);/* Annotate some text */$draw->annotation(20, 50, 'Hello World!');/* Create a new canvas object and a white image */$canvas = new Imagick();$canvas->newImage(350, 70, 'white');/* Draw the ImagickDraw on to the canvas */$canvas->drawImage($draw);/* 1px black border around the image */$canvas->borderImage(’black’, 1, 1);/* Set the format to PNG */$canvas->setImageFormat(’png’);/* Output the image */header('Content-Type: image/png');echo $canvas;?>

以上例程的輸出類似于:

PHP擴展之圖像處理3——ImageMagick使用及相關類和方法

Example #5 Read in GIF image and resize all frames

<?php/* Create a new imagick object and read in GIF */$im = new Imagick('example.gif');/* Resize all frames */foreach ($im as $frame) {/* 50x50 frames */$frame->thumbnailImage(50, 50);/* Set the virtual canvas to correct size */$frame->setImagePage(50, 50, 0, 0);}/* Notice writeImages instead of writeImage */$im->writeImages('example_small.gif', true);?>

Example #6 Create a PHP logo

<?php/* Set width and height in proportion of genuine PHP logo */$width = 400;$height = 210;/* Create an Imagick object with transparent canvas */$img = new Imagick();$img->newImage($width, $height, new ImagickPixel(’transparent’));/* New ImagickDraw instance for ellipse draw */$draw = new ImagickDraw();/* Set purple fill color for ellipse */$draw->setFillColor(’#777bb4’);/* Set ellipse dimensions */$draw->ellipse($width / 2, $height / 2, $width / 2, $height / 2, 0, 360);/* Draw ellipse onto the canvas */$img->drawImage($draw);/* Reset fill color from purple to black for text (note: we are reusing ImagickDraw object) */$draw->setFillColor(’black’);/* Set stroke border to white color */$draw->setStrokeColor(’white’);/* Set stroke border thickness */$draw->setStrokeWidth(2);/* Set font kerning (negative value means that letters are closer to each other) */$draw->setTextKerning(-8);/* Set font and font size used in PHP logo */$draw->setFont(’Handel Gothic.ttf’);$draw->setFontSize(150);/* Center text horizontally and vertically */$draw->setGravity(Imagick::GRAVITY_CENTER);/* Add center 'php' with Y offset of -10 to canvas (inside ellipse) */$img->annotateImage($draw, 0, -10, 0, ’php’);$img->setImageFormat(’png’);/* Set appropriate header for PNG and output the image */header(’Content-Type: image/png’);echo $img;?>

以上例程的輸出類似于:

PHP擴展之圖像處理3——ImageMagick使用及相關類和方法相關類及方法請參閱:http://www.php.net/manual/zh/book.imagick.php
標簽: PHP
相關文章:
主站蜘蛛池模板: 国产1区在线观看 | 香蕉在线观看视频 | 激情性生活视频在线播放免费观看 | 三级很黄很黄的视频 | 国产精品视频一区二区三区不卡 | 特级一级毛片免费看 | 加勒比一本一道在线 | 国产色视频在线 | 91精品国产高清91久久久久久 | 女人被男人狂躁免费视频 | 日韩精品欧美一区二区三区 | 午夜精品同性女女 | 性色毛片免费视频 | 欧美一级网址 | 中国欧美日韩一区二区三区 | 国产a不卡片精品免费观看 国产a毛片高清视 | 国产妞干网 | 欧美精品久久久久久久久大尺度 | 一级做a爰片性色毛片小说 一级做a爰片性色毛片中国 | 亚洲精品成人456在线播放 | 欧美一级大黄特黄毛片视频 | 91免费永久国产在线观看 | 一级视频在线观看免费 | 欧美亚洲一区二区三区四 | 妞干网这里只有精品 | 高清一本视频在线观看 | 欧洲1区二区三区二页 | 九九精品视频免费 | 国产在线精品观看一区 | 成人亚洲精品一区二区 | 久久ri精品高清一区二区三区 | 亚洲精品在线播放视频 | 成人午夜精品久久不卡 | 欧美性黑人巨大gaysex | 国产精品98福利小视频 | 国产午夜精品久久久久免费视小说 | 无内丝袜透明在线播放 | 一级毛片免费播放视频 | 黄色网址你懂的 | 国产精品国产三级在线高清观看 | 免费网站看av片 |