Login Retreive lost passwordRegister
Search

Forum Index / General / MergeImage with transparencey

[ This topic is solved ]

  Geoff 18 January 06 / 16:17  
I'm trying to re-size and then add a logo to a picture that is uploaded via FormHandler.

All is working fine except that I cant get any transparency on the logo. I've tried the logo as a gif and as a png file and I've tried using array(0,0,0) and array(255,255,255) and neither the black or the white on the logo becomes transparent.

Is there something obvious I'm missing?

Code is:
<?php 
$form->UploadField("Your photo".$req, "photo", $piccfg);
$form->resizeImage("photo", NULL, $max_x, $max_y, 100);
$form->mergeImage("photo", $_SERVER['DOCUMENT_ROOT']."/images/wm.gif", "right", "bottom", array(0,0,0));
?>

  Teye Heimans (Founder) 18 January 06 / 16:20  
The "stamp" which you are using should become transparant, not the image itsself. Are you aware of that?

  Geoff 18 January 06 / 16:37  
Yes the "stamp" or logo is circular and I want the corners of the stamp image to be transparent. but the corners remain resolutly solid.

  Teye Heimans (Founder) 19 January 06 / 08:47  
sorry, my bad. I've tested this with a png stamp because I could not get it working with a gif stamp.

  Geoff 19 January 06 / 09:46  
And it works with a png stamp?
I did try a png stamp and coildn't get it to work selecting a transparent colour.
Or did you mean to use a png file that has alpha transparency already set?

  Teye Heimans (Founder) 26 January 06 / 11:46  
If you just test with your own script (http://nl3.php.net/manual/nl/function.imagecolortransparent.php) does it work then ?

  Geoff 28 January 06 / 00:48  
I will try that and get back to you.

  Teye Heimans (Founder) 05 February 06 / 12:41  
ok

  Geoff 05 February 06 / 14:00  
Changed at 05 February 06 / 14:01
Hmmmmm - no it doesn't seem to work outside of Formhandler either. Code is below, am I doing anything wrong?

<?php
$back = imagecreatefromjpeg('/home/mb/public_html/testback.jpg');
$logo = imagecreatefromgif('/home/mb/public_html/testlogo.gif');
$bwidth = 300;
$bheight = 418;
$lwidth = 150;
$lheight = 17;
$new = imageCreateTrueColor($bwidth, $bheight);
ImageCopy( $new, $back, 0,0,0,0, $bwidth, $bheight );
$white = imageColorAllocate($logo,255,255,255);
imageColorTransparent($logo,$white);
imageCopyMerge($new, $logo, 10, 10, 0, 0, $lwidth, $lheight, 100);
header("Content-Type: image/jpeg");
header("Content-Disposition: attachment; filename=image_name.jpg"); // THIS ONE
imageJpeg($new,'',100);
?>

  Teye Heimans (Founder) 10 February 06 / 10:32  
I cant get it to work either with gif files. Maybe Im doing something wrong...

  Geoff 10 February 06 / 11:11  
I'll try the simple version with a png as well - but I do seem to remember that I tried pngs when I was first experimenting with it.

  Geoff 13 February 06 / 10:36  
Just tried pngs again with that simplified version changing the line

$logo = imagecreatefromgif('/home/mb/public_html/testlogo.gif');
to
$logo = imagecreatefrompng('/home/mb/public_html/testlogo.png');

(and creating an appropriate png file obviously)

Same result - no transparency, can anyone get it to work on their system?

  Teye Heimans (Founder) 18 February 06 / 09:17  
I have tested the script below and came to the following conclusion:
- Gif files won't work (Tried with: resizeIMG and resizeIMG)
- JPG files won't work (resizeIMG)
- PNG files work if you export them as PNG24 format (dont ask me what that is.. I use photoshop.) PNG8 format isn't working
This one works (png24): resizeIMG
This one isn't (png8): resizeIMG

I hope that this solves the problem.

<?php


$original = $_SERVER['DOCUMENT_ROOT'] . "/images/Image.jpg";

$stamp    = $_SERVER['DOCUMENT_ROOT'] . "/images/stamp/png24.png";

// red color transparant
$aTransparant = array(
  255, # red
  0, # green
  0  # blue
);

// open the current file (get the resource )
$rImgSrc = imagecreatefromjpeg( $original );

// get the size of the image
$aSize = getimagesize( $original );

// create the "new" file recourse (the destination)
$rImgDest = imagecreatetruecolor( $aSize[0], $aSize[1] );

// open the stamp image (get the resource)
$rImgStamp = imagecreatefrompng( $stamp );

// transparant color...
if( is_array($aTransparant) )
{
    $color = ImageColorAllocate( $rImgStamp, $aTransparant[0], $aTransparant[1], $aTransparant[2] );
    ImageColorTransparent( $rImgStamp, $color );
}

// copy the current file to the new one
ImageCopy( $rImgDest, $rImgSrc, 0,0,0,0, $aSize[0], $aSize[1] );

// delete the resource of the original
ImageDestroy( $rImgSrc );

// get the size of the stamp
$x = ImageSX( $rImgStamp );
$y = ImageSY( $rImgStamp );

// X and Y position on the original!
$posX = 100;
$posY = 100;

// copy the stamp to the new image
ImageCopyMerge( $rImgDest, $rImgStamp, $posX, $posY, 0, 0, $x, $y, 100 );
//ImageCopy( $rImgDest, $rImgStamp, $posX, $posY, 0, 0, $x, $y );  # transparant isnt working!
//ImageCopyResampled( $rImgDest, $rImgStamp, 0, 0, $x, $y, $x, $y ); # transparant isnt working!

ImageDestroy( $rImgStamp );

header('Content-Type: image/png');
// Save the new image
imagepng( $rImgDest, '', 100 );
ImageDestroy( $rImgDest );


?>

  Geoff 07 March 06 / 12:59  
Sorry about the big delay - but yes - using PNG24 format did sort it out for me. A note for the new manual I guess ;-).

  Teye Heimans (Founder) 07 March 06 / 13:10  
 Quote: Geoff
 
Sorry about the big delay - but yes - using PNG24 format did sort it out for me. A note for the new manual I guess ;-).


ok!

  Top


powered by PHP-GLOBE   © 2004 - 2026 FormHandler. All rights reserved.   -   Open source license