lipe009 Posted October 24, 2012 Share Posted October 24, 2012 (edited) I need a system in PHP that the user upload an image and it automatically puts a mask on top of this image (like, for example, a border). I tried to use some watermark scripts but none of them it's exactly what i need (since the two images, at the end, need to be in the same dimensions). Can anybody help me with this? Thanks! Edited October 24, 2012 by lipe009 Quote Link to comment https://forums.phpfreaks.com/topic/269841-upload-and-put-a-mask-in-php/ Share on other sites More sharing options...
MDCode Posted October 24, 2012 Share Posted October 24, 2012 There's a freelancer section for this. At least make an attempt first if you post here Quote Link to comment https://forums.phpfreaks.com/topic/269841-upload-and-put-a-mask-in-php/#findComment-1387350 Share on other sites More sharing options...
lipe009 Posted October 24, 2012 Author Share Posted October 24, 2012 There's a freelancer section for this. At least make an attempt first if you post here And i did, a lot attempts! It shouldn't be that hard, that's why it doesn't need a freelancer. Quote Link to comment https://forums.phpfreaks.com/topic/269841-upload-and-put-a-mask-in-php/#findComment-1387351 Share on other sites More sharing options...
MDCode Posted October 24, 2012 Share Posted October 24, 2012 But you're asking for completed code...I'm sure help can be found if you post what you've tried so far Quote Link to comment https://forums.phpfreaks.com/topic/269841-upload-and-put-a-mask-in-php/#findComment-1387352 Share on other sites More sharing options...
lipe009 Posted October 24, 2012 Author Share Posted October 24, 2012 Let's say that we already uploaded the image with the name test.jpg. Now i want to resize the image to 1280x886px and put a mask on top of it. This mask is also 1280x886px large. This is how i did it: <?php $srcimg = "test.jpg"; //the source file $tmimg = "test2.jpg"; //name of the new one $wmimg = "mask.png"; //the mask files $waterlevel = 100; //the level of opacity //load the jpeg and get its sizes $image = 1280; $size = 886; //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 new_img sizes $newwidth = 1280; $newheight = 886; //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 mask 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/269841-upload-and-put-a-mask-in-php/#findComment-1387353 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.