image - Trying to generate 3D bumpmap text in PHP -


i have website monetize numerous original pictures on it, want people visit website see original pictures , have search engines show pictures transparent watermarks.

the following example of mean transparent watermark. except of course, replace "test!" company name.

bumpmap

here's php code created far:

<?php $txt = "test!"; header( "content-type: image/jpeg", true );  $w  = imagefontwidth(5) * ( strlen( $txt ) + 1 ); $h  = imagefontheight(5) * 2; $i2 = imagecreatetruecolor( $w,$h );  imagesavealpha( $i2, true ); imagealphablending( $i2, false ); imagefill( $i2, 0, 0, imagecolorallocatealpha( $i2, 255, 255, 255, 127 ) ); imagestring( $i2, 3, 10, 10, $txt, imagecolorallocate( $i2, 255, 0, 0) ); $i = imagecreatefromjpeg( "someimage.jpg" ); imagecopyresized( $i, $i2, 2, 2, 0, 0, $w * 5, $h * 7, $w, $h ); imagejpeg( $i, null, 100 ); imagedestroy( $i ); imagedestroy( $i2 ); ?> 

$i2 resource variable image box in added text, , $i1 large image place text on. $w , $h represent width , height of text image box. code able produce text on top of image without background box showing, doesn't produce bump-map effect shown in above image.

can guide me functions, mathematics or code need use create bump-map effect?

i feel solution requires special manipulation of block of pixels don't know how effect.

i want stick php gd image library.

i'd recommend using semi-transparent png , adding watermark rather using imagestring functions.

with imagestring functions you'd theoretically needs create 2 strings, 1 higher , left other, , somehow calculate pixels both strings present , make transparent. mean left-over parts black / white , give 3d effect.

example 1

if watermark same each image, can use semi-transparent png. benefit of allows far more effects, , result better result.

<?php  // watermark take 80% of photo's width $size = 80;  $im = imagecreatefromjpeg(dirname(__file__) . '/photo.jpg'); $oi = imagecreatefrompng(dirname(__file__) . '/watermark.png'); $w1 = imagesx($im); $h1 = imagesy($im); $w2 = imagesx($oi); $h2 = imagesy($oi);  $w = $w1 - (($w1 / 100) * (100 - $size)); $h = ($w * $h2) / $w2;  imagecopyresampled($im, $oi, $w1 / 2 - $w / 2, $h1 / 2 - $h / 2, 0, 0, $w, $h, $w2, $h2);  header('content-type: image/jpg'); imagejpeg($im, null, 100); imagedestroy($im); 

will produce following output:

output

original photo / watermark

example 2

if watermark needs different each image, can use imagettftext create text using font of choosing (much better imagestring limited effects can do).

<?php  $size = 55; $angle = 15; $text = uniqid(); $font = 'bebasneue.otf'; // http://www.dafont.com/bebas-neue.font  $im = imagecreatefromjpeg(dirname(__file__) . '/photo.jpg'); $w = imagesx($im); $h = imagesy($im);  $text_colour_1 = imagecolorallocatealpha($im, 0, 0, 0, 99); $text_colour_2 = imagecolorallocatealpha($im, 255, 255, 255, 90); $box = imagettfbbox($size, $angle, dirname(__file__) . '/' . $font, $text); imagettftext($im, $size, $angle, (($w - $box[4]) / 2) - 1, (($h - $box[5]) / 2) - 1, $text_colour_1, dirname(__file__).'/' . $font, $text); imagettftext($im, $size, $angle, ($w - $box[4]) / 2, ($h - $box[5]) / 2, $text_colour_2, dirname(__file__).'/' . $font, $text);  header('content-type: image/jpg'); imagejpeg($im, null, 100); 

output:

output


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -