简体   繁体   English

如何使用php-imagick缩放和裁剪图像?

[英]How to scale and crop an image with php-imagick?

I use jQuery Guillotine to position a preloaded image. 我使用jQuery Guillotine来定位预加载的图像。 Guillotine returns an array similar to this one: 断头台返回一个类似于这个的数组:

array (
    'scale' => '0.13186813186813187',
    'angle' => '0',
    'x' => '45',
    'y' => '0',
    'w' => '180',
    'h' => '180'
)

Now I can crop the image like this: 现在我可以像这样裁剪图像:

$url = 'https://s.yimg.com/uy/build/images/sohp/inspiration/love-rock3.jpg';

$image = new Imagick();
$image->readImageFile(fopen($url, 'rb'));
$image->cropImage($size['w'], $size['h'], $size['x'], $size['y']);

header("Content-Type: image/jpg");
echo $image->getImageBlob();

But how to zoom in? 但是如何放大? I have scale which is the zoom factor I guess. 我有scale ,我猜这是缩放因子。 Does Imagick provide a way to pass a zoom factor? Imagick是否提供了传递缩放系数的方法?

Not sure what you mean with zoom? 不确定你对zoom的意思? You want to scale the picture to a specific width and height? 您想将图片缩放到特定的宽度和高度吗?

Manual: http://php.net/manual/en/book.imagick.php 手册: http//php.net/manual/en/book.imagick.php

to crop and resize an image in one step take a closer look at this: http://php.net/manual/en/imagick.cropimage.php#119086 只需一步即可裁剪和调整图像大小,请仔细查看: http//php.net/manual/en/imagick.cropimage.php#119086

imagick has zooming by crop. 想象力已经缩小了作物。 It is called the crop zoom. 它被称为裁剪缩放。 You shall read it from here before implementing. 在实施之前,您应该从这里阅读。 http://www.imagemagick.org/discourse-server/viewtopic.php?t=18065 http://www.imagemagick.org/discourse-server/viewtopic.php?t=18065

Here you will find the examples as well. 在这里你也可以找到这些例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM