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条)

报告相同问题?

悬赏问题

  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题