php - font size depending image size -


i'm sorry english! i've problem imagick php , overlay text on image. size of font small when resize width of image. example 2 image width, first 350px , second 1728px: http://i.stack.imgur.com/8kro0.jpg http://i.stack.imgur.com/teddo.jpg

$f->userfontsize size of font logged user choose show on image.

if(trim($_get['full']) != 'si'){ $width = 350; $height = 350; } else { $width =    getwidth($root . $f->imagepathfull); $height =     getheight($root . $f->imagepathfull); } $image = new imagick(); $draw = new imagickdraw(); $pixel = new imagickpixel('white'); $image->newimage($width, $height, $pixel); $image->readimage($root . $f->imagepathnormal);  $image->resizeimage ( $width, $height,  imagick::filter_lanczos, 1, true); $fontpath = $root . '/assets/fonts/mermaid.ttf'; $draw->setfillcolor('black'); $draw->setfont($fontpath); $draw->setfontsize(12 + $f->userfontsize); $draw->setgravity(1); $draw->settextantialias(true); $draw->setfillopacity(".55"); $image->annotateimage($draw, 5,0, 0, "text text text"); $image->setimageformat("jpg");  header( "content-type: image/jpeg" ); echo $image->getimageblob(); $image->clear(); 

when print image resolution 1728px text small. how do increase font size depending image size? thank you! :)

i've solved way, calculated percentage of width text occupy on image @ 350px , according calculated percentage @ 1728px(or width). cicle font size until when find size egual @ percentage. final result of solution non perfect acceptable. code:

$mycp = '40'; // increase o decrease font size. for($i = 1; $i <= 500;$i++){     $box = imagettfbbox($i, 0, $fontpath, "lorem ipsum");     $lt = $box[2] - $box[0];     $cp = round(($lt / $width) * 100,1);     // $cp percentage of font width     if($cp >= $mycp) { $newfontsize = $i; break; } else { continue; } }  

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -