lipe009 Posted October 23, 2012 Share Posted October 23, 2012 I want to make a code in PHP that resize and place a watermark on the image resized. There is this code: $srcimg = "thebigphoto.jpg"; //the source file $tmimg = "sm_".$srcimg; //were to place the thumb $wmimg = "watermark.pbr"; //the watermark files $target = 150; //thumbnail target size $waterlevel = 40; //the level of opacity //load the jpeg and get its sizes $image = imagecreatefromjpeg($srcimg); $size = getimagesize($srcimg); //this if just figures out what side is dominant if ($size[0] > $size[1]) { $percentage = ($target / $size[0]); } else { $percentage = ($target / $size[1]); } //calc the thumb sizes $newwidth = round($size[0] * $percentage); $newheight = round($size[1] * $percentage); //make a new img | copy the smaller | save as jpeg | clean up $thumb = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $size[0], $size[1]); imagejpeg($thumb,$tmimg); imagedestroy($thumb); //make watermage img | and get its sizes; $watermark = imagecreatefrompng($wmimg); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); //this will place it Bottom-Left, 5px from the border $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; //copy it over | save it over the original | and clean up imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $waterlevel); imagejpeg($image,$srcimg ); imagedestroy($watermark); imagedestroy($image); It does not work, though. Dreamweaver shows syntax errors in the code. Can someone tell me what is wrong in the code? Quote Link to comment https://forums.phpfreaks.com/topic/269799-watermark-and-automatic-resize-image/ Share on other sites More sharing options...
vbnullchar Posted October 23, 2012 Share Posted October 23, 2012 got it working.. put the water first then resize. $srcimg = "test.jpg"; //the source file $tmimg = "sm_".$srcimg; //were to place the thumb $wmimg = "hack.png"; //the watermark files $target = 150; //thumbnail target size $waterlevel = 40; //the level of opacity //load the jpeg and get its sizes $image = imagecreatefromjpeg($srcimg); $size = getimagesize($srcimg); //make watermage img | and get its sizes; $watermark = imagecreatefrompng($wmimg); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); //this will place it Bottom-Left, 5px from the border $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; //copy it over | save it over the original | and clean up imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, $waterlevel); //this if just figures out what side is dominant if ($size[0] > $size[1]) { $percentage = ($target / $size[0]); } else { $percentage = ($target / $size[1]); } //calc the thumb sizes $newwidth = round($size[0] * $percentage); $newheight = round($size[1] * $percentage); //make a new img | copy the smaller | save as jpeg | clean up $thumb = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($thumb, $image, 0, 0, 0, 0, $newwidth, $newheight, $size[0], $size[1]); imagejpeg($thumb, $tmimg); imagedestroy($thumb); imagedestroy($watermark); imagedestroy($image); Quote Link to comment https://forums.phpfreaks.com/topic/269799-watermark-and-automatic-resize-image/#findComment-1387143 Share on other sites More sharing options...
lipe009 Posted October 24, 2012 Author Share Posted October 24, 2012 (edited) got it working.. put the water first then resize. Thanks, the code did worked. I didn't use it, though, since it didn't help to what I was thinking: http://forums.phpfre...-a-mask-in-php/ Edited October 24, 2012 by lipe009 Quote Link to comment https://forums.phpfreaks.com/topic/269799-watermark-and-automatic-resize-image/#findComment-1387347 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.