N
N
newaitix2018-02-01 21:18:48
Layout
newaitix, 2018-02-01 21:18:48

Position the image in the center of the block?

Get the price of the product

$prefix1='88Qn|Q*wcIa5';
$prefix2='{Rvi#wy?r?#1';
$price=77777;
$encode="$prefix1$price$prefix2";
$encode=urlencode(base64_encode($encode));
echo"<img src='text_to_img.php?text=$encode' height='26px' width='200px'>";

text_to_img.php
$prefix1='88Qn|Q*wcIa5';
$prefix2='{Rvi#wy?r?#1';
$get=$_GET['text'];
$get=base64_decode(urldecode($get));
$prefixs=array($prefix1,$prefix2);
$get=str_replace($prefix1,"",$get);
$get=str_replace($prefix2,"",$get);
$get=strrev(implode(' ',str_split(strrev($get), 3)));
$result=$get.' грн.';
if(isset($result)&&!empty($result)){
  $image=imagecreatetruecolor(200,26);
  $background=imagecolorallocate($image,255,255,255);
  $color=imagecolorallocate($image,57,181,74);
  $font_file='arial.ttf';
  imagefilledrectangle($image,0,0,299,99,$background);
  imagefttext($image,17,0,0,21,$color,$font_file,$result);
  header('Content-Type:image/png');
  imagepng($image);
  imagedestroy($image);
}

In imagefttext, the indent is from the left, the indent is from the top. It looks like this.
5a735986e9556874045128.png
Now a question. Is it possible to make it so that, regardless of the width of the generated image, the text in the image is always located exactly in the center?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2018-02-01
@sim3x

https://www.w3schools.com/css/css_align.asp

img {
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: 40%;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question