Ejemplo n.º 1
0
 public static function pad(\Imagine\Gd\Image $img, \Imagine\Image\Box $size, $fcolor = [255, 255, 255], $ftransparency = 0)
 {
     $tsize = $img->getSize();
     $x = $y = 0;
     if ($size->getWidth() > $tsize->getWidth()) {
         $x = round(($size->getWidth() - $tsize->getWidth()) / 2);
     }
     if ($size->getHeight() > $tsize->getHeight()) {
         $y = round(($size->getHeight() - $tsize->getHeight()) / 2);
     }
     $pasteto = new \Imagine\Image\Point($x, $y);
     $imagine = new \Imagine\Gd\Imagine();
     $palette = new \Imagine\Image\Palette\RGB();
     $color = new \Imagine\Image\Palette\Color\RGB($palette, $fcolor, $ftransparency);
     $image = $imagine->create($size, $color);
     $image->paste($img, $pasteto);
     return $image;
 }
Ejemplo n.º 2
0
function generate_image($image, $typeobj, $id)
{
    global $faker;
    $image->setTitle(getRealText(20))->setDescription(getRealText(250))->setChapo(getRealText(40))->setPostscriptum(getRealText(40))->setFile(sprintf("sample-image-%s.png", $id))->save();
    $palette = new \Imagine\Image\Palette\RGB();
    // Generate images
    $imagine = new Imagine\Gd\Imagine();
    $image = $imagine->create(new Imagine\Image\Box(320, 240), $palette->color('#E9730F'));
    $white = $palette->color('#FFF');
    $font = $imagine->font(__DIR__ . '/faker-assets/FreeSans.ttf', 14, $white);
    $tbox = $font->box("THELIA");
    $image->draw()->text("THELIA", $font, new Imagine\Image\Point((320 - $tbox->getWidth()) / 2, 30));
    $str = sprintf("%s sample image", ucfirst($typeobj));
    $tbox = $font->box($str);
    $image->draw()->text($str, $font, new Imagine\Image\Point((320 - $tbox->getWidth()) / 2, 80));
    $font = $imagine->font(__DIR__ . '/faker-assets/FreeSans.ttf', 18, $white);
    $str = sprintf("%s ID %d", strtoupper($typeobj), $id);
    $tbox = $font->box($str);
    $image->draw()->text($str, $font, new Imagine\Image\Point((320 - $tbox->getWidth()) / 2, 180));
    $image->draw()->line(new Imagine\Image\Point(0, 0), new Imagine\Image\Point(319, 0), $white)->line(new Imagine\Image\Point(319, 0), new Imagine\Image\Point(319, 239), $white)->line(new Imagine\Image\Point(319, 239), new Imagine\Image\Point(0, 239), $white)->line(new Imagine\Image\Point(0, 239), new Imagine\Image\Point(0, 0), $white);
    $image_file = sprintf("%s/media/images/%s/sample-image-%s.png", THELIA_LOCAL_DIR, $typeobj, $id);
    if (!is_dir(dirname($image_file))) {
        mkdir(dirname($image_file), 0777, true);
    }
    $image->save($image_file);
}
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public static function create(Imagine\Image\BoxInterface $size, Imagine\Image\Palette\Color\ColorInterface $color = null)
 {
     return static::$instance->create($size, $color);
 }