Set different font sizes with imagettftext()

591 views Asked by At

Is it possible to set different font-sizes on the images within one imagettftext()?

I have managed to output the needed text on the image. Now, I want to show the $subheadliner_thu_1 in larger font-size. I don't want to put it in a new imagettftext(), because the length of the text could change in the future. So, set coordinates should not be used for $undercard_thu_4.

Here is my code:

<?php
  header('Content-type: image/jpeg');
  $jpg_image = imagecreatefromjpeg('img/pkp-empty.jpg');
  $white = imagecolorallocate($jpg_image, 255, 255, 255);
  $font_path = 'fonts/calibri.ttf';

  $undercard_thu_1 = "amelie lens";
  $undercard_thu_1 = strtoupper($undercard_thu_1);
  $undercard_thu_2 = "beautifull swimmers";
  $undercard_thu_2 = strtoupper($undercard_thu_2);
  $undercard_thu_4 = "cypress hill";
  $undercard_thu_4 = strtoupper($undercard_thu_4);
  $subheadliner_thu_1 = "chance the rapper";
  $subheadliner_thu_1 = strtoupper($subheadliner_thu_1);

  $lineup_upper1 = $undercard_thu_1 . ' • ' . $undercard_thu_2;
  $lineup1 = wordwrap($lineup_upper1, 60, "\n", false);

  $lineup_upper2 = $subheadliner_thu_1 . ' • ' . $undercard_thu_4;
  $lineup2 = wordwrap($lineup_upper2, 60, "\n", false);

  imagettftext($jpg_image, 25, 0, 295, 532, $white, $font_path, $lineup1);
  imagettftext($jpg_image, 25, 0, 72, 579, $white, $font_path, $lineup2);

  imagejpeg($jpg_image);
  imagedestroy($jpg_image);
?>
0

There are 0 answers