Jump to content

[SOLVED] imagecopymerge transparent PNG


EagerWolf

Recommended Posts

I would like to make new jpg from png-24 and another jpg file.

 

Thre problem is i want to put transparent image over my image but it shows as it wasn't transparent.

 

I've used:

imagecopymerge($croped, $merged_img, $x_zamik, $y_zamik,0 ,0, $framed_img_h,$framed_img_w , 100);

 

$croped = my transparent image

$merged = my jpg image

 

Other thinks are just to show position... and I've set pic to 100 ...

 

Also I've tried to set pic to 99 and swap images, so $merged_img was on first place...

 

Thanks for your help!

Link to comment
Share on other sites

Can you post up the rest of your script? Have you switched on alpha blending with imagealphablending()?

 

If you are outputting an jpg, regardless of what the "bottom" file is, it will not have transparency.

The transparent png would be layered before outputting as a jpeg, as I understood it.

Link to comment
Share on other sites

As adobe puts it on this page...http://www.adobe.com/support/fireworks/optimize/optimize_jpeg/ :

 

The JPEG format does not support transparency. However, you can simulate background transparency in a JPEG by choosing a Matte color that exactly matches the Web page background color on which the JPEG will appear.

 

 

Link to comment
Share on other sites

Yes Yes ... everything ok ...

 

What I was asking was:

 

You have got ... PNG Photo and PNG frame...

 

Than you merge PNG Photo and PNG frame into one file using imagecopymerge... Images should be merged correctly... And they are outputed correctly as jpeg... Of course jpeg can not be used as transparent image...

 

I've understood if image is outputed as JPG, than PNG files will loose their transparency when you try to merge. But this doesn't sound possible. Or is it?

Link to comment
Share on other sites

I can't believe people are not understanding what is required here.

 

Image 1: A photograph

Image 2: A frame with a transparent center

 

The OP wants to layer the frame over the photograph, with the photograph showing through, then saving the resulting image as a jpeg. If this is what you are trying to do, and as I have understood it throughout this post, yes, I believe it is possible. As for jpeg not supporting transparency, that is 100% correct, but by the time the image is ready to be output to jpeg, there is no remaining transparency!

 

I'm just getting ready to leave for the office, when I get there, I'll write up a quick demo script - If I remember!

Link to comment
Share on other sites

Here's some code...

<?php
$photo = imagecreatefrompng("photo.png");
$w = imagesx($photo);
$h = imagesy($photo);
imagealphablending($photo,true);

$frame = imagecreatefrompng("frame.png");
imagecopy($photo,$frame,0,0,0,0,$w,$h);

imagejpeg($photo,"output.jpg",100);
?>
 

Here's the inputs and output:

[images removed]

Edited by requinix
removed images at author's request
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.