Jump to content

Image Processing


chxxangie

Recommended Posts

First load your two images:

 

$image1 = imagecreatefrompng('image1.png');
$image2 = imagecreatefrompng('image2.png');

 

Then create your new image calculating the width and height from the previous two images. If you want the images side-by-side, the width of the new image will be the width of the first image plus the width of the second image.

 

$new_image_width = imagesx($image1) + imagesx($image2);
$new_image_height = max(imagesy($image1), imagesy($image2)); // Make height the height of the taller image.
$new_image = imagecreatetruecolor($new_image_width, $new_image_height);

 

Finally, copy the two images onto your new image and output the image.

 

imagecopy($new_image, $image1, 0, 0, 0, 0, imagesx($image1), imagesy($image1));
imagecopy($new_image, $image2, imagesx($image1), 0, 0, 0, imagesx($image2), imagesy($image2));

imagepng($new_image);

 

See imagecopy() for more information.

Link to comment
Share on other sites

<?php
$image1 = imagecreatefromjpeg("images/thumbs/my_image-thumb.jpg");
$image2 = imagecreatefromjpeg("template_new.jpg");

$new_image_width = imagesx($image2);
$new_image_height = imagesy($image2); 
$new_image = imagecreatetruecolor($new_image_width, $new_image_height);

imagecopy($new_image, $image1, 0, 0, 0, 0, imagesx($image2), imagesy($image2));
imagecopy($new_image, $image2, 0, 0, 0, 0, imagesx($image2), imagesy($image2));

imagejpeg($new_image,'final2.jpg');

?>

 

my $image2 can be said is the background. then, i want to make $image1 overlap to $image2 and follow $image2 width and height. so $image1 need to resize to the same size with $image2.

i try to modify the code. but the result come out is only $iamge2 without $image1.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.