Jump to content

black watermark


ricmetal

Recommended Posts

hi guys

i need some help

i am trying to create a resized image with a watermark, from an uploaded image..

the image is getting uploaded and resized but the watermark doesnt appear correct.

instead of a transparent watermark, there's a black square in it's place.

this is my code

$tempfile = $_FILES['filename']['tmp_name'];
$src = imagecreatefromjpeg($tempfile);
list($origWidth, $origHeight) = getimagesize($tempfile);
// creating png image of watermark
$watermark = imagecreatefrompng('../imgs/watermark.png');
// getting dimensions of watermark image
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
// placing the watermark
$dest_x = $origWidth / 2 - $watermark_width / 2;
$dest_y = $origHeight / 2 - $watermark_height / 2;
imagecopyresampled($src, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $origWidth, $origHeight);
imagealphablending($src, true);
imagealphablending($watermark, true);
imagejpeg($src,$galleryPhotoLocation,100); // $galleryPhotoLocation is correct. the image gets uploaded successfully..

 

 

Link to comment
Share on other sites

so i managed to get the script working with imagecopy, instead of imagecopyresampled.

but i don't understand the difference between the two. could anyone explain? thanks

 

Have you tried reading the manual for those two functions?

http://php.net/manual/en/function.imagecopyresampled.php

http://us3.php.net/manual/en/function.imagecopy.php

 

And I don't mean just skimming the description. Typically, if there are certain issues that can be encountered with a function the information is there if you take the time to read it. Specifically, I see this in the manual page for imagecopyresampled()

Note:

 

There is a problem due to palette image limitations (255+1 colors). Resampling or filtering an image commonly needs more colors than 255, a kind of approximation is used to calculate the new resampled pixel and its color. With a palette image we try to allocate a new color, if that failed, we choose the closest (in theory) computed color. This is not always the closest visual color. That may produce a weird result, like blank (or visually blank) images. To skip this problem, please use a truecolor image as a destination image, such as one created by imagecreatetruecolor().

 

I don't know if that is the cause of the problem you experienced, but it definitely sounds like a possibility.

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.