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

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)