Php - Imagick Fit Text into rectangle
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Bounty: create php function that writes text into a specified rectangle area, and automatically adjusts the font-size to get the best fit. The font-size should automatically adjust to match the rectangle size. The more text, the smaller the font. The less text, the bigger the font should be. The text should fill the rectangle as much as possible.

Function signature:
function writeTextInRectangle(\Imagick() $image, string $text,
int $offsetX, int $offsetY, int $width, int $height,
string $textAlignment, string $fontColor, string $fontFamily) {...}

  • This function will write text into the rectangle specified by starting point ($offsetX, $offsetY) and has width $width, and height $height, on top of image $image \Imagick.
  • $image: the base image (\Imagick object).
  • $textAlignment: "left"."right","centered", "justified" should be the available options and should specify the alignment of text
  • $fontColor: will specify color of written text. Default: "Century Gothic".
  • $fontFamily: will specify family of written text. Default: black.

An almost complete solution is here:

I need this solution converted to PHP, using Imagick PHP extension, and having the signature defined above.

Working live sample must be provided as a link.

System: Php 5.6

Crowdsource coding tasks.

0 Solutions