Generate image thumbnails with watermarks on the fly in PHP -
i'm looking php class (solution) generating image thumbnails watermarks on fly. idea ?
i've used code add text (thumbnail) image:
(note you'll need provide font)
function createimage($in_filename, $out_filename, $width, $height) { $src_img = imagecreatefromjpeg($in_filename); $old_x = imagesx($src_img); $old_y = imagesy($src_img); $dst_img = imagecreatetruecolor($width, $height); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $old_x, $old_y); addwatermark($dst_img); imagejpeg($dst_img, $out_filename, 80); imagedestroy($dst_img); imagedestroy($src_img); } function addwatermark($image) { $text = "watermark text"; $font = realpath($_server["document_root"] . "/code/courbd.ttf"); // case sensitive if ($font == false) return; $fontsize = 11; $borderoffset = 4; $dimensions = imagettfbbox($fontsize, 0, $font, $text . "@"); $linewidth = ($dimensions[2] - $dimensions[0]); $textx = (imagesx($image) - $linewidth) / 2; $texty = $borderoffset - $dimensions[7]; $white = imagecolorallocate($image, 240, 240, 240); imagettftext($image, $fontsize, 0, $textx, $texty, $white, $font, $text); }
feedback welcome.
Comments
Post a Comment