Imagick::cropImage - Manual - PHP
Có thể bạn quan tâm
update page now
↑ and ↓ to navigate • Enter to select • Esc to close • / to open Press Enter without selection to search using Google
- Downloads
- Documentation
- Get Involved
- Help
-
- PHP 手册
- 函数参考
- 图像生成和处理
- ImageMagick
- Imagick
(PECL imagick 2, PECL imagick 3)
Imagick::cropImage — 截图图片的一块区域
说明
public Imagick::cropImage( int $width, int $height, int $x, int $y): bool截图图片的一块区域
参数
width
截图的宽度
height截图的高度
x裁剪区域左上角的 X 轴坐标(以原图的左上角为原点)
y裁剪区域左上角的 X 轴坐标(以原图的左上角为原点)
返回值
成功时返回 true。
错误/异常
错误时抛出 ImagickException。
示例
示例 #1 Imagick::cropImage()
<?phpfunction cropImage($imagePath, $startX, $startY, $width, $height) { $imagick = new \Imagick(realpath($imagePath)); $imagick->cropImage($width, $height, $startX, $startY); header("Content-Type: image/jpg"); echo $imagick->getImageBlob();}?>发现了问题?
了解如何改进此页面 • 提交拉取请求 • 报告一个错误 +添加备注用户贡献的备注 4 notes
up down 17 Christian Dehning ¶15 years ago When cropping gif-images (I had no problems with jpg and png images), the canvas is not removed. Please run the following command on the cropped gif, to remove the blank space: $im->setImagePage(0, 0, 0, 0); up down 5 olav at schettler dot net ¶9 years ago Here is a simple function to create a thumbnail. It accepts an additional parameter to set the focus point of the generated thumbnail: <?php function thumbnail($image, $new_w, $new_h, $focus = 'center') { $w = $image->getImageWidth(); $h = $image->getImageHeight(); if ($w > $h) { $resize_w = $w * $new_h / $h; $resize_h = $new_h; } else { $resize_w = $new_w; $resize_h = $h * $new_w / $w; } $image->resizeImage($resize_w, $resize_h, Imagick::FILTER_LANCZOS, 0.9); switch ($focus) { case 'northwest': $image->cropImage($new_w, $new_h, 0, 0); break; case 'center': $image->cropImage($new_w, $new_h, ($resize_w - $new_w) / 2, ($resize_h - $new_h) / 2); break; case 'northeast': $image->cropImage($new_w, $new_h, $resize_w - $new_w, 0); break; case 'southwest': $image->cropImage($new_w, $new_h, 0, $resize_h - $new_h); break; case 'southeast': $image->cropImage($new_w, $new_h, $resize_w - $new_w, $resize_h - $new_h); break; } } ?> up down 5 ElPadre ¶15 years ago Actually, the Imagick::setImagePage(0,0,0,0) is also handy with jpgs and pngs, if you plan to do any more changes on the cropped image that involves positioning and/or gravity (I created a script that does crop, face blur and watermarking in one go, and had a hell of a time determining why the blurs and the watermark text never showed up...). up down -2 oxxido at gmail dot com ¶10 years ago I have a function that takes an image, resize and crop it, and save it as normal, then resize it again and crop it again to create the thumbnail. The numbers of the second crop were WAY off, and the calculations were perfect, the problem, was the second crop wasn't resetting the imagePage, so if you try to crop the same image twice, it will be a good idea to reset it first: <?php $thumb = new Imagick($file) $thumb->resizeImage($r_w1,$r_h1,Imagick::FILTER_CATROM,0.9, false); $thumb->cropImage($w1,$h1,$l1,$t1); $thumb->writeImage($destinationPath.'/'.$fileName); $thumb->resizeImage($r_w2,$r_h2,Imagick::FILTER_CATROM,0.9, false); $thumb->setImagePage(0, 0, 0, 0); $thumb->cropImage($w2,$h2,$l2,$t2); $thumb->writeImage($destinationPath.'/'.$fileNameThumb); ?> BTW, i needed perfect dimentions so i had to set the "bestfit" to false. +添加备注Từ khóa » T2 Thumb Gif
-
Terminator 2 Thumbs Up GIFs - Tenor
-
Terminator Thumbs Up GIFs | Tenor
-
Arnold Schwarzenegger Thumbs Up GIF By Karla Delakidd - GIPHY
-
Best T 2 Thumbs Up GIFs - Gfycat
-
Best Terminator 2 Thumbs GIFs - Gfycat
-
Terminator 2 Terminator Thumbs Up GIF On GIFER - By Vizahn
-
T2: Terminator Gives Death The Thumbs Up - Make A Gif
-
T2: Terminator Gives Death The Thumbs Up
-
[PDF] GIF Thumbnails: Attract More Clicks To Your Videos - AAAI Publications
-
T2 Thumbs Up Memes - Imgflip
-
T2 Thumbs Up Blank Template - Imgflip
-
T2: Terminator Gives Death The Thumbs Up - YouTube
-
Screwdriver | Translate To Traditional Chinese: Cambridge Dictionary