我如何在php中使用imagick? (调整大小和作物)

前端之家收集整理的这篇文章主要介绍了我如何在php中使用imagick? (调整大小和作物)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用imagick的缩略图作品,但有时裁剪的缩略图缺少图像的顶部(头发,眼睛).

我正在考虑调整图像的大小,然后裁剪.另外,我需要保持图像的大小比例.

以下是我用于作物的PHP脚本:

  1. $im = new imagick( "img/20130815233205-8.jpg" );
  2. $im->cropThumbnailImage( 80,80 );
  3. $im->writeImage( "thumb/th_80x80_test.jpg" );
  4. echo '<img src="thumb/th_80x80_test.jpg">';

谢谢..

这个任务并不容易,因为“重要”部分可能并不总是在同一个地方.仍然使用这样的东西
  1. $im = new imagick("c:\\temp\\523764_169105429888246_1540489537_n.jpg");
  2. $imageprops = $im->getImageGeometry();
  3. $width = $imageprops['width'];
  4. $height = $imageprops['height'];
  5. if($width > $height){
  6. $newHeight = 80;
  7. $newWidth = (80 / $height) * $width;
  8. }else{
  9. $newWidth = 80;
  10. $newHeight = (80 / $width) * $height;
  11. }
  12. $im->resizeImage($newWidth,$newHeight,imagick::FILTER_LANCZOS,0.9,true);
  13. $im->cropImage (80,80,0);
  14. $im->writeImage( "D:\\xampp\\htdocs\\th_80x80_test.jpg" );
  15. echo '<img src="th_80x80_test.jpg">';

(测试)

应该工作cropImage参数(0和0)决定裁剪区域的左上角.所以玩这些给你不同的结果留在图像.

猜你在找的PHP相关文章