PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How to implement imagecopy (GD) function by Imagick?

 October 11, 2022     gd, imagemagick, imagick, php     No comments   

Issue

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.


Solution

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();


Answered By - Lukas Nagel
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing