Example #1
0
 public function renderImage()
 {
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     $lightColor = new \ImagickPixel('LightCoral');
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor($lightColor);
     $draw->setStrokeWidth(2);
     $draw->setFontSize(36);
     $draw->setFont("../fonts/Arial.ttf");
     $draw->annotation(50, 50, "Lorem Ipsum!");
     $msg = "Danack";
     $xpos = 0;
     $ypos = 0;
     list($lines, $lineHeight) = wordWrapAnnotation($imagick, $draw, $msg, 140);
     for ($i = 0; $i < count($lines); $i++) {
         $imagick->annotateImage($draw, $xpos, $ypos + $i * $lineHeight, 0, $lines[$i]);
     }
     header("Content-Type: image/jpg");
     echo $imagick->getImageBlob();
 }
Example #2
0
 function renderImage()
 {
     /* Implement word wrapping... Ughhh... why is this NOT done for me!!!
            OK... I know the algorithm sucks at efficiency, but it's for short messages, okay?
        
            Make sure to set the font on the ImagickDraw Object first!
            @param image the Imagick Image Object
            @param draw the ImagickDraw Object
            @param text the text you want to wrap
            @param maxWidth the maximum width in pixels for your wrapped "virtual" text box
            @return an array of lines and line heights
        */
     function wordWrapAnnotation(\Imagick $imagick, $draw, $text, $maxWidth)
     {
         $words = explode(" ", $text);
         $lines = array();
         $i = 0;
         $lineHeight = 0;
         while ($i < count($words)) {
             $currentLine = $words[$i];
             if ($i + 1 >= count($words)) {
                 $lines[] = $currentLine;
                 break;
             }
             //Check to see if we can add another word to this line
             $metrics = $imagick->queryFontMetrics($draw, $currentLine . ' ' . $words[$i + 1]);
             while ($metrics['textWidth'] <= $maxWidth) {
                 //If so, do it and keep doing it!
                 $currentLine .= ' ' . $words[++$i];
                 if ($i + 1 >= count($words)) {
                     break;
                 }
                 $metrics = $imagick->queryFontMetrics($draw, $currentLine . ' ' . $words[$i + 1]);
             }
             //We can't add the next word to this line, so loop to the next line
             $lines[] = $currentLine;
             $i++;
             //Finally, update line height
             if ($metrics['textHeight'] > $lineHeight) {
                 $lineHeight = $metrics['textHeight'];
             }
         }
         return array($lines, $lineHeight);
     }
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     $lightColor = new \ImagickPixel('LightCoral');
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor($lightColor);
     $draw->setStrokeWidth(2);
     $draw->setFontSize(36);
     $draw->setFont("../fonts/Arial.ttf");
     $draw->annotation(50, 50, "Lorem Ipsum!");
     $msg = "Danack";
     $xpos = 0;
     $ypos = 0;
     list($lines, $lineHeight) = wordWrapAnnotation($imagick, $draw, $msg, 140);
     for ($i = 0; $i < count($lines); $i++) {
         $imagick->annotateImage($draw, $xpos, $ypos + $i * $lineHeight, 0, $lines[$i]);
     }
     header("Content-Type: image/jpg");
     echo $imagick->getImageBlob();
 }
Example #3
0
File: icon.php Project: EQ4/DRR
    return $hue;
}
$height = 1715;
$width = 1715;
$image = new Imagick('../images/radio-backdrop_1715.png');
$draw = new ImagickDraw();
$hue = tint_bg($image, $show);
$draw->setFont('DejaVu-Sans-Bold');
$draw->setFontSize(get_font_size($show));
$draw->setStrokeColor("black");
$draw->setFillColor("white");
$draw->setStrokeWidth(6);
//max(min(18 * (450 / $out_res), 30), 6));
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);
list($parts, $height) = wordWrapAnnotation($image, $draw, $show, 1635);
// If we only have one line then we can leave it centered.
if (count($parts) > 1) {
    $draw->setTextAlignment(imagick::ALIGN_LEFT);
    $draw->setGravity(imagick::GRAVITY_NORTH);
    $ix = 0;
    $offset = 40;
} else {
    $draw->setGravity(imagick::GRAVITY_CENTER);
    $ix = -1;
    $offset = 0;
}
foreach ($parts as $line) {
    $image->annotateImage($draw, $offset, ($ix + 1) * $height, 0, $line);
    $ix++;
}