gerkintrigg Posted July 13, 2007 Share Posted July 13, 2007 Hello everyone. I'd like some advice about watermarking and resizing. i have a script that will do almost all i need, but it generates a new image and saves it in a "result" folder each time the script runs, and it's bunging up my server. Would you suggest to use a cron to clear the folder on a daily basis or change the script so the output image is downloaded then deleted? Any help'd be much appreciated. Regards, Neil Quote Link to comment https://forums.phpfreaks.com/topic/59769-watermarking-resize-without-saving/ Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 Are you using PHP to resize the image each time it is loaded? That's a real strain on the CPU. Otherwise, post the original code you're using and we'll try to modify it to fit your needs. Quote Link to comment https://forums.phpfreaks.com/topic/59769-watermarking-resize-without-saving/#findComment-297140 Share on other sites More sharing options...
gerkintrigg Posted July 13, 2007 Author Share Posted July 13, 2007 you're probably right... so you think that I should just resize and watermark once and then reference the re-sized, watermarked image? Quote Link to comment https://forums.phpfreaks.com/topic/59769-watermarking-resize-without-saving/#findComment-297168 Share on other sites More sharing options...
MadTechie Posted July 13, 2007 Share Posted July 13, 2007 if you post the code you use to create the image we can help.. or just create anothe file called image.php give it a image header and read the image inn.. image.php?src=myimage.jpg you also need the image "watermark.png" (reason for the png is the transparency) <?php header('content-type: image/jpeg'); $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg($_GET['src']); $size = getimagesize($_GET['src']); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); ?> Quote Link to comment https://forums.phpfreaks.com/topic/59769-watermarking-resize-without-saving/#findComment-297173 Share on other sites More sharing options...
infid3l Posted July 13, 2007 Share Posted July 13, 2007 you're probably right... so you think that I should just resize and watermark once and then reference the re-sized, watermarked image? Exactly. An easy solution is naming the new file something like "originalname_thumb.jpg" then when you run image.php, it will only resize and watermark if the file does not exist already. Post your code! Quote Link to comment https://forums.phpfreaks.com/topic/59769-watermarking-resize-without-saving/#findComment-297179 Share on other sites More sharing options...
darknessmdk Posted August 24, 2007 Share Posted August 24, 2007 MadTechie I tried your code you posted and it put a white and black box on my test image. I used a transparent png file Quote Link to comment https://forums.phpfreaks.com/topic/59769-watermarking-resize-without-saving/#findComment-333004 Share on other sites More sharing options...
MadTechie Posted August 24, 2007 Share Posted August 24, 2007 Ahh ok, this will work.. (kinda forgot the alphachannel) header('content-type: image/jpeg'); $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg($_GET['src']); imagealphablending($image, true); $size = getimagesize($_GET['src']); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); ?> Quote Link to comment https://forums.phpfreaks.com/topic/59769-watermarking-resize-without-saving/#findComment-333012 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.