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 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示