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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog