drsrq26482 2012-12-23 12:01
浏览 82
已采纳

如何通过Imagick实现imagecopy(GD)功能?

I'm working with imagick and face some problem. I want to composite two images: image01 and image02,image01 is background image,a part of image02 composite on image01. the function just like GD's imagecopy function.

bool imagecopy( resource dst_im, resource src_im, int dst_x, int dst_y, 
                int src_x, int src_y,int src_w, int src_h )

Copy a part of src_im onto dst_im starting at the x,y coordinates src_x, src_y with a width of src_w and a height of src_h. The portion defined will be copied onto the x,y coordinates, dst_x and dst_y.

the question is: how to implement imagecopy function by Imagick?

thanks for your help.

  • 写回答

2条回答 默认 最新

  • dswy34539 2012-12-31 09:46
    关注

    This should do it:

    //load files from source
    $background = new Imagick(image01_src);
    $overlay = new Imagick(image02_src);
    
    //Crop the overlay to the required size
    $overlay->cropImage ($new_width,$new_height,$x_offset,$y_offset);
    
    //composite overlay on background
    $background->compositeImage($overlay, Imagick::COMPOSITE_OVER, $margin_x, $margin_y);
    
    //save result
    $background->setImageFormat("png");
    $background->writeImage(new_src);
    
    //clean up
    $background->clear();
    $background->destroy();
    $overlay->clear();
    $overlay->destroy();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?