Jump to content

Recommended Posts

Hi,

I'm just getting into creating and manipulating images on the server side, and was hoping the community could point me in the direction of a function that would allow me to stack 3 GIF images (created using @ImageCreate etc) on top of one another whilst maintaining their transparencies.

When i say on top of one another, i dont mean in the z-index sence, so that the image remains the same size, but is a merge of the 3. Rather i want to have 3 images (for example 50pixels high and 100px wide, to be stacked together into a single resulting image that is 150px high, by 100px wide.

The best function i can find is imagecopymerge i think, but i cannot figure out how to use that in the manor i desire.

Thanks in advance of your help.

Tom
Link to comment
https://forums.phpfreaks.com/topic/30636-combining-gif-images/
Share on other sites

Thanks, I'm getting closer!

I've created 3 images, and saved them to the server. I now want to combine these images into one. I've written the following function to do this, but at the moment all i am ending up with is a black box.

I think my problem might be one of the following, but i don't know how to solve any of them.

1) I'm not openning the files in the correct way to turn them into a resource again.
2) I'm not setting the background of my new image to be transparent
3) Something else.

Any further advice much appreciated.

T

[code]
function create_combined_images($file_name, $target_folder, $image1, $image2, $image3)
{
$mime_type = 'image/gif' ;
$extension = '.gif' ;
$send_buffer_size = 4096 ;

// create image
$size = getimagesize($image1);
$image = @ImageCreate($size[0], 150) ;
if(!$image || !$size)
{
fatal_error('Error: The server could not create this heading image.');
}

$file1 = @fopen($image1,'rb');
imagecopymerge ($image, $file1, 0, 0, 0, 0, $size[0], $size[1], 100);

$file2 = @fopen($image2,'rb');
$size = getimagesize($image2);
imagecopymerge ($image, $file2, 0, 50, 0, 0, $size[0], $size[1], 100);

$file3 = @fopen($image3,'rb');
$size = getimagesize($image3);
imagecopymerge ($image, $file3, 0, 100, 0, 0, $size[0], $size[1], 100);

// save copy of image
$save_filename = $target_folder . '/' . $file_name . $extension ;
echo "<br/>save file name: " . $save_filename;
@ImageGIF($image,$save_filename);

ImageDestroy($image);
}
[/code]

[i]A side question to this is what difference does adding a "@" to the front of the image function make? It seems to work the same with or without?[/i]
Link to comment
https://forums.phpfreaks.com/topic/30636-combining-gif-images/#findComment-141656
Share on other sites

Update::

I'm pretty sure that i am just not reading in the image file correctly in order for it to be an image "resource". Please could someone advise me how i can read a file and convert it into a php image resource.

Thanks!

Tom

My updated function is below.

[code]function create_combined_images($file_name, $target_folder, $image1, $image2, $image3, $background_color, $transparent_background)
{
$mime_type = 'image/gif' ;
$extension = '.gif' ;
$send_buffer_size = 4096 ;

// create image
$size = getimagesize($image1);
$image = @ImageCreate($size[0], 150) ;
if(!$image || !$size)
{
fatal_error('Error: The server could not create this heading image.');
}

$file1 = @fopen($image1,'rb');
imagecopymerge ($image, $file1, 0, 0, 0, 0, $size[0], $size[1], 100);

$file2 = @fopen($image2,'rb');
$size = getimagesize($image2);
imagecopymerge ($image, $file2, 0, 50, 0, 0, $size[0], $size[1], 100);

$file3 = @fopen($image3,'rb');
$size = getimagesize($image3);
imagecopymerge ($image, $file3, 0, 100, 0, 0, $size[0], $size[1], 100);

$background_rgb = hex_to_rgb($background_color) ;
$background_color = @ImageColorAllocate($image,$background_rgb['red'],
$background_rgb['green'],$background_rgb['blue']) ;
// set transparency
if($transparent_background)
ImageColorTransparent($image,$background_color) ;

// save copy of image
$save_filename = $target_folder . '/' . $file_name . $extension ;
echo "<br/>save file name: " . $save_filename;
@ImageGIF($image,$save_filename);

ImageDestroy($image);
}[/code]

Please help!
Link to comment
https://forums.phpfreaks.com/topic/30636-combining-gif-images/#findComment-141803
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.