phpQuestioner Posted August 26, 2007 Share Posted August 26, 2007 I am not quit sure how to use imagecopyresized with this script or exactly how to change the width and height. Could some one give me a little guidance on this one? <?php // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script // where this script is named watermark.php // call this script with an image tag // <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg $imagesource = $_GET['path']; $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); if($filetype == ".png") $image = @imagecreatefrompng($imagesource); if (!$image) die(); $watermark = @imagecreatefromgif('08-25-2007.GIF'); $imagewidth = imagesx($image); $imageheight = imagesy($image); $watermarkwidth = imagesx($watermark); $watermarkheight = imagesy($watermark); $startwidth = (($imagewidth - $watermarkwidth)/2); $startheight = (($imageheight - $watermarkheight)/2); imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); ?> Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/ Share on other sites More sharing options...
MadTechie Posted August 26, 2007 Share Posted August 26, 2007 height and width of what ? the image $imagewidth = imagesx($image); $imageheight = imagesy($image); or the watermark $watermarkwidth = imagesx($watermark); $watermarkheight = imagesy($watermark); Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334230 Share on other sites More sharing options...
phpQuestioner Posted August 26, 2007 Author Share Posted August 26, 2007 mainly just this: $imagewidth = imagesx($image); $imageheight = imagesy($image); But I also may need to resize this two: $watermarkwidth = imagesx($watermark); $watermarkheight = imagesy($watermark); So that the watermark will be centered - not sure about that - still playing around with/learning GD. Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334233 Share on other sites More sharing options...
MadTechie Posted August 26, 2007 Share Posted August 26, 2007 Okay... i don't get the question! to double it do $imagewidth = imagesx($image)*2; $imageheight = imagesy($image)*2; ??? Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334234 Share on other sites More sharing options...
phpQuestioner Posted August 26, 2007 Author Share Posted August 26, 2007 I want to resize it say from 640X480 to 500X400 I tried this: <?php $imagewidth = imagesx($image)-140; $imageheight = imagesy($image)-80; ?> but then it changed the location of my watermark actually it did not even display watermark at all and it did not resize it either Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334235 Share on other sites More sharing options...
MadTechie Posted August 26, 2007 Share Posted August 26, 2007 try this addition imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); // Resize after merge $newwidth = 500; $newheight = 400; $resized= imagecreatetruecolor($newwidth, $newheight); imagecopyresized($resized, $image, 0, 0, 0, 0, $newwidth, $newheight, $imagewidth , $imageheight); imagedestroy($image); $image = $resized; EDIT: added two lines Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334238 Share on other sites More sharing options...
phpQuestioner Posted August 26, 2007 Author Share Posted August 26, 2007 ok - i tried it like this: <?php // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script // where this script is named watermark.php // call this script with an image tag // <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg $imagesource = $_GET['path']; $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); if($filetype == ".png") $image = @imagecreatefrompng($imagesource); if (!$image) die(); $watermark = @imagecreatefromgif('08-25-2007.GIF'); $imagewidth = imagesx($image); $imageheight = imagesy($image); $watermarkwidth = imagesx($watermark); $watermarkheight = imagesy($watermark); $startwidth = (($imagewidth - $watermarkwidth)/2); $startheight = (($imageheight - $watermarkheight)/2); imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); // Resize after merge $newwidth = 500; $newheight = 400; $resized= imagecreatetruecolor($newwidth, $newheight); imagecopyresized($resized, $image, 0, 0, 0, 0, $newwidth, $newheight, $imagewidth , $imageheight); //imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); ?> but nothing happened.......... Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334240 Share on other sites More sharing options...
MadTechie Posted August 26, 2007 Share Posted August 26, 2007 change imagejpeg($image); imagedestroy($image); imagedestroy($watermark); to imagejpeg($resized); imagedestroy($image); imagedestroy($watermark); imagedestroy($resized); Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334242 Share on other sites More sharing options...
phpQuestioner Posted August 26, 2007 Author Share Posted August 26, 2007 Thank You MadTechie - I figured out what I was doing wrong. <?php // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script // where this script is named watermark.php // call this script with an image tag // <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg $imagesource = $_GET['path']; $filetype = substr($imagesource,strlen($imagesource)-4,4); $filetype = strtolower($filetype); if($filetype == ".gif") $image = @imagecreatefromgif($imagesource); if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource); if($filetype == ".png") $image = @imagecreatefrompng($imagesource); if (!$image) die(); $watermark = @imagecreatefromgif('08-25-2007.GIF'); $imagewidth = imagesx($image); $imageheight = imagesy($image); $watermarkwidth = imagesx($watermark); $watermarkheight = imagesy($watermark); $startwidth = (($imagewidth - $watermarkwidth)/2); $startheight = (($imageheight - $watermarkheight)/2); imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); // Resize after merge $newwidth = 500; $newheight = 400; $resized= imagecreatetruecolor($newwidth, $newheight); imagecopyresized($resized, $image, 0, 0, 0, 0, $newwidth, $newheight, $imagewidth , $imageheight); //imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); imagejpeg($resized); imagedestroy($resized); imagedestroy($watermark); ?> Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334243 Share on other sites More sharing options...
MadTechie Posted August 26, 2007 Share Posted August 26, 2007 quick note add imagedestroy($image); to the end, to release the memory (don't want memory leakage) Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334246 Share on other sites More sharing options...
phpQuestioner Posted August 26, 2007 Author Share Posted August 26, 2007 MadTechie - I will be sure to put that in - Thanks Again!!! Quote Link to comment https://forums.phpfreaks.com/topic/66711-solved-how-to-use-imagecopyresized-with-this-water-mark-script/#findComment-334250 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.