ricmetal Posted December 15, 2011 Share Posted December 15, 2011 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 https://forums.phpfreaks.com/topic/253196-black-watermark/ Share on other sites More sharing options...
ricmetal Posted December 15, 2011 Author Share Posted December 15, 2011 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 Link to comment https://forums.phpfreaks.com/topic/253196-black-watermark/#findComment-1298189 Share on other sites More sharing options...
Psycho Posted December 15, 2011 Share Posted December 15, 2011 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 https://forums.phpfreaks.com/topic/253196-black-watermark/#findComment-1298191 Share on other sites More sharing options...
ricmetal Posted December 15, 2011 Author Share Posted December 15, 2011 thanks damato that's probably it. i should read the manual in more detail! Link to comment https://forums.phpfreaks.com/topic/253196-black-watermark/#findComment-1298195 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.