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
https://forums.phpfreaks.com/topic/130189-image-processing/#findComment-675146
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
https://forums.phpfreaks.com/topic/130189-image-processing/#findComment-675198
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.