FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Merging jpeg and (transparent) png using php GD





flatliner
Hi there

I have been seaching through http://ie.php.net/manual/en/ref.image.php and messing around with functions such as

Code:
imagecopymerge  ( resource $dst_im  , resource $src_im  , int $dst_x  , int $dst_y  , int $src_x  , int $src_y  , int $src_w  , int $src_h  , int $pct  )


I can get the two images to merge, but I have a problem. I need the jpeg to be behind the png and it to be transperent. So that you can see the jpeg behind the png. Anyone got a script that might do somthing like this or know of a more helpful function? I have been seaching for two days for this, so I dont want people posting the url to php.net/manual. I have looked and googled alot before I came here.

Kind Regards
Ciaran Mc Cann
Stubru Freak
I think this comment can help you: http://ie.php.net/manual/en/function.imagecopy.php#84306
kv
If you are trying to put a jpeg under a transparent gif to prevent user from saving the jpeg, you can do it using simple html/css by setting jpeg as background (yes that is right jpeg as background) and png as the image. If user tries to save it, he will save foreground png, but for viewing purpose, jpeg is still visible.
flatliner
Thanks Stubru Freak for the link, I just looked at it briefly, but looks promising thanks.

kv wrote:
If you are trying to put a jpeg under a transparent gif to prevent user from saving the jpeg, you can do it using simple html/css by setting jpeg as background (yes that is right jpeg as background) and png as the image. If user tries to save it, he will save foreground png, but for viewing purpose, jpeg is still visible.

No its actually not for a water mark, its for an application that allows you to but your own photo in, for example in a wanted poster, monkey body etc. The template would be a png and most likely image upload by the user would be a jpeg. Thanks anyway, I didn't know about that.
flatliner
I had a look at that link and it did help abit, I picked up the below code there I think. I have made one or two changes to it. It works, in that it allows the jpeg in the background to be seen through the png, but I cant seem to get position the certain area of the jpeg I wish to see.

Also the new image takes on the width and height of the background image which is the jpeg. I have been messing around with this bit of code for a while trying different things, but I still cant manipulate the 2 images.

Code:


<?php
/* Attempt to overlay transparent and semi-transparent images */
$width = 800;
$height = 600;

$dst_width = 800;
$dst_height = 600;

$bottom_image = imagecreatefromjpeg("images/water.jpg");
$top_image = imagecreatefrompng("admin/templates/thumb_8212648.png");
imagesavealpha($top_image, false);
imagealphablending($top_image, false);
imagecopy($bottom_image, $top_image, 0, 0, 0, 0, $width, $height);
imagepng($bottom_image, "new_image.png");
?>




Anymore idea's or feedback?? Confused thanks
Related topics
[tutor] How to protect images without htaccess using PHP
Using PHP
Includ Images using PHP.
How to start using PHP? Help!
Website Designing using PHP
how can i setup a page break for printer on html using php ?
Reading word documents using PHP?
I am trying to build a contact form using php and flash
Communicating between web pages
how to compress a file using php ?
Checking if ports are up using PHP
Images with an invisible background.
Hot to change "Reset Ownership" using php?
Using php to change content of a .txt
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.