iNko Posted March 23, 2012 Share Posted March 23, 2012 Hello again, i need to do a form that uploads an image, makes a thumbnail of it and puts a watermark image and text on the thumbnail.. Iv managed to do the uploading part, making the thumbnail, then making a watermarked thumbnail (with image) , and i need some help with the watermark text part.. What im thinking of - generate a text image, then apply it to the watermark, then add the watermark with text to the thumbnail. This is the function i used for the watermark image: <?php function watermark($original_image,$original_watermark,$destination="") { $image=imagecreatefromjpeg($original_image); list($imagewidth,$imageheight)=getimagesize($original_image); $watermark = imagecreatefrompng($original_watermark); list($watermarkwidth,$watermarkheight)=getimagesize($original_watermark); if($watermarkwidth>$imagewidth || $watermarkheight>$imageheight) { $water_resize_factor = $imagewidth / $watermarkwidth; $new_watermarkwidth = $watermarkwidth * $water_resize_factor; $new_watermarkheight = $watermarkheight * $water_resize_factor; $new_watermark = imagecreatetruecolor($new_watermarkwidth , $new_watermarkheight); imagealphablending($new_watermark , false); imagecopyresampled($new_watermark , $watermark, 0, 0, 0, 0, $new_watermarkwidth, $new_watermarkheight, $watermarkwidth, $watermarkheight); $watermarkwidth = $new_watermarkwidth; $watermarkheight = $new_watermarkheight; $watermark = $new_watermark; } $startwidth = ($imagewidth - $watermarkwidth) / 2; $startheight = ($imageheight - $watermarkheight) / 2; imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); if(!empty($destination)) imagejpeg($image,$destination); else imagejpeg($image); } ?> Can i insert in this function something like this? (the "Text" would appear on top of the watermark image in the middle) : <?php // Create the canvas $canvas = imagecreate( 150, 80 ); // First colour - this will be the default colour for the canvas // $light_blue = imagecolorallocate( $canvas, 176, 226, 255 ); // The second colour - to be used for the text $black = imagecolorallocate( $canvas, 0, 0, 0 ); // Path to the font you are going to use $font = "verdana.ttf"; // Text to write $text = "Text"; // Font size $size = "40"; // Add the text to the canvas imageTTFText( $canvas, $size, 0, 15, 60, $black, $font, $text ); // Save as Text.jpg imagejpeg( $canvas, "Text.jpg" ); // Clear the memory of the tempory image ImageDestroy( $canvas ); ?> Thx in advance. Link to comment https://forums.phpfreaks.com/topic/259572-having-trouble-with-watermarking-an-image/ Share on other sites More sharing options...
QuickOldCar Posted March 23, 2012 Share Posted March 23, 2012 http://www.roseindia.net/tutorial/php/phpgd/About-watermark.html Link to comment https://forums.phpfreaks.com/topic/259572-having-trouble-with-watermarking-an-image/#findComment-1330544 Share on other sites More sharing options...
iNko Posted March 23, 2012 Author Share Posted March 23, 2012 http://www.roseindia.net/tutorial/php/phpgd/About-watermark.html This is not what im looking for.. i already did the part with the watermark IMAGE.. i need to generate a text on top of my watermark image Link to comment https://forums.phpfreaks.com/topic/259572-having-trouble-with-watermarking-an-image/#findComment-1330552 Share on other sites More sharing options...
litebearer Posted March 23, 2012 Share Posted March 23, 2012 http://php.net/manual/en/function.imagettftext.php Link to comment https://forums.phpfreaks.com/topic/259572-having-trouble-with-watermarking-an-image/#findComment-1330559 Share on other sites More sharing options...
iNko Posted March 24, 2012 Author Share Posted March 24, 2012 i tried but it just shows some weird symbols on my browser, ignores the text part completely, and just uploads with image watermark only this is where i tried to write the code, idk if this is where i need to write smth, or i need to create a new function or smth.. $imw = imagesx($im); // uploaded image width $imh = imagesy($im); // uploaded image height $nh = $thumbnailheight; // thumbnail height $nw = round(($nh / $imh) * $imw); //thumnail width $newim = imagecreatetruecolor ($nw, $nh); ////////////THE TEXT WATERMARK PART///////////////////// $textim = imagecreatetruecolor ($nw, $nh); //creates image //$white = imagecolorallocate($textim, 255, 255, 255); //$grey = imagecolorallocate($textim, 128, 128, 128); $black = imagecolorallocate($textim, 0, 0, 0); //creates black color $start_x = $nh / 2; //possition where the text will be placed (in this case middle of thumbnail) $start_y = $nw / 2; //imagefilledrectangle($textim, 0, 0, 399, 29, $white); //$text = 'Testing'; //$font = 'Dunkin.ttf'; //imagettftext($textim, 20, 0, 11, 21, $grey, $font, $text); imagettftext($textim, 5, 0, $start_x, $start_y, $black, 'Dunkin.ttf', "text"); //adds the text, with size 5, possition middle of thumbnail, black color, font 'dunkin', and text "text" //imagettftext($textim, 20, 0, 10, 20, $black, $font, $text); imagepng($textim); //????? imagedestroy($textim); //????? /////////////////////////////////////////// imagecopyresampled ($newim,$im, 0, 0, 0, 0, $nw, $nh, $imw, $imh) ; $thumbfilename = $thumbnailfolder.$uploadfilename ; Link to comment https://forums.phpfreaks.com/topic/259572-having-trouble-with-watermarking-an-image/#findComment-1330719 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.