dongxiang5879 2016-02-25 22:10
浏览 71
已采纳

如何使用来自jQuery Guillotine Plugin和Imagick的数据裁剪图像

I've searched everywhere for two days now, still no help.

my project uses jQuery Guillotine Plugin to allow users select image size and position before uploading to my php server but i can't figure out the proper way to crop and scale the image based on the data received from the frontend.

Here is what i've tried:

The response i'm trying to work with looks like this:

{ scale: 0.324, angle: 0, x: 110, y: 34, w: 300, h: 300 }

Then the php code:

$imagick = Image::make($destination . "/" . $fileName);
$height = $imagick->height();
$width = $imagick->width();

$imagick->rotate($req['angle']);
//using the data recieved after user selection
$imagick->cropImage((int)$req['w'], (int)$req['h'], (int)$req['x'], (int)$req['y']);
//Write image to disk
$imagick->save($destinationPathSmaller . $fileName);

At this point, the picture doesn't display correctly. i really don't know what to do, this is my 3rd day on this. please help!

Thanks in inadvance,

  • 写回答

2条回答 默认 最新

  • duanjiaonie6097 2016-02-26 07:43
    关注

    Okay, so i finally got it working.

    I thank everyone that tried to help, here is what i did in case someone else is faced with same issue:

    Using Intervention and Imagick as the driver.

    After collecting your data from the guillotine API, process it and use it like this.

    $imagick = Image::make($destination . "/" . $fileName);
    $width = $imagick->width() * $req['scale'];
    
    $imagick->rotate($req['angle']);
    $imagick->widen($width);
    
    //Crop to desired width and height. 
    //Note: the width and height has to be same with what you set on your Guillotine config when instantiating it. 
    $imagick->crop($req['w'], $req['h'], $req['x'], $req['y']);
    
    //Finally, Save your file
    $imagick->save($new_destination . $fileName);
    

    That should just work perfectly.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办