I want to merge 2 images with imagick.
I already know how to merge them with imagick, but I need to pass 2 variables through wp_get_image_editor to get this to work.

I named the 2 variables $background and $logo. $background contains the background image path. $logo contains the logo image path.

Does anyone know how I should do this?

  • 2
    Please show us some actual code.
    – kaiser
    Oct 23, 2013 at 20:40
  • @kaiser I just need to know how I should pass 2 variables (file paths) through wp_get_image_editor(). But I added some code to explain: <?php $background = // Background file path $logo = // Logo file path $image = wp_get_image_editor( $file, array( 'methods' => array( 'mergephotos' ) ) ); // QUESTION: In my case I want $file to contain 2 images. $image->mergephotos(); // Mergephotos(); is running something like this $file1->compositeImage($file2, Imagick::COMPOSITE_DEFAULT, 0, 0); to merge thise photos. Check out: codex.wordpress.org/Class_Reference/WP_Image_Editor Oct 24, 2013 at 7:37
  • Lasse, did you see the edit link? Also show use the Mergephotos() and compositeImage() content.
    – kaiser
    Oct 24, 2013 at 12:47
  • @kaiser I don't understand what you need Mergephotos and compositeImages() when the question is how to pass 2 variables through wp_get_image_editor.. compositeImage is default in imagick: php.net/manual/en/imagick.compositeimage.php and mergephotos() is a "method" in my class that extends WP_Image_Editor_Imagick, so I can get the Imagick::compositeImage to work in wp. Oct 24, 2013 at 14:16
  • Because you might have a XY Problem and doing it another way might be easier. And as I said: Please edit your question and remove the comment containing the code to prevent comment explosion.
    – kaiser
    Oct 24, 2013 at 14:18

1 Answer 1


Mike Schroder said:

"WP_Image_Editor is built to handle one file at a time, and there isn’t anything built in to combine two images by default.

The main reason here is that the files in-memory aren’t compatible with one-another if different editors (say, GD and Imagick) are used for each.

There are a few different ways to handle it, of course, but one way to solve the problem here would be to load one of the two images, then extend the Imagick editor (or both editors, if you prefer more compatibilty) to support combining images. Say, with a $image->combine( ‘filename’ ) method.

First, you’d load one of the images with wp_get_image_editor() (and specify that ‘combine’ is a required method), then call your combine method while specifying the second image."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.