<?php
// Das Gesamtbild vorbereiten
$im = new Imagick();
// Das erste Bild vorbereiten
$im1 = new Imagick(realpath('images/2015-02-28_Gegensteine_03.jpg'));
$wimg = $im1->getImageWidth();
// Text einfügen
$draw = new ImagickDraw();
/* Textfarbe */
$draw->setFillColor('white');
/* Font properties */
$draw->setFont('fonts/Skia.ttf');
$draw->setFontSize(10);
$draw->setTextAlignment(Imagick::ALIGN_CENTER);
/* Text zeichnen */
$im1->annotateImage(
$draw,
$wimg / 2,
45,
0,
'The quick brown fox jumps over the lazy dog'
);
// Das zweite Bild vorbereiten
$im2 = new Imagick(realpath('images/2015-02-28_Gegensteine_05.jpg'));
// Beide Bilder dem Gesamtbild hinzu fügen
$im->addImage($im1);
$im->addImage($im2);
$im->resetIterator();
$combined = $im->appendImages(true);
// base64-Format vorbereiten
$imgBuff = $combined->getimageblob();
/**
* This clears the image.jpg resource from our $img object and destroys the
* object. Thus, freeing the system resources allocated for doing our image
* manipulation.
*/
$im->clear();
/**
* This creates the base64 encoded version of our unencoded string from
* earlier. It is then output as an image to the page.
*
* Note, that in the src attribute, the image/jpeg part may change based on
* the image type you're using (i.e. png, jpg etc).
*/
// Das Bild in einem img-Tag anzeigen
echo '<img alt="Embedded Image" src="data:image/jpeg;base64,' . base64_encode($imgBuff) . '">';
?>