示例#1
0
文件: overlay.php 项目: kus/php-image
<?php

require_once '../src/PHPImage.php';
$bg = './img/benji.jpg';
$overlay = './img/paw.png';
$image = new PHPImage();
$image->setDimensionsFromImage($bg);
$image->draw($bg);
$image->draw($overlay, '50%', '75%');
$image->rectangle(40, 40, 120, 80, array(0, 0, 0), 0.5);
$image->setFont('./font/arial.ttf');
$image->setTextColor(array(255, 255, 255));
$image->setStrokeWidth(1);
$image->setStrokeColor(array(0, 0, 0));
$image->text('Hello World!', array('fontSize' => 12, 'x' => 50, 'y' => 50));
$image->text('This is a big sentence with width 200px', array('fontSize' => 60, 'x' => 300, 'y' => 0, 'width' => 200, 'height' => 50, 'alignHorizontal' => 'center', 'alignVertical' => 'center', 'debug' => true));
$image->text('This is a big sentence', array('fontSize' => 60, 'x' => 300, 'y' => 200, 'width' => 200, 'height' => 50, 'alignHorizontal' => 'center', 'alignVertical' => 'center', 'debug' => true));
$image->textBox('Lorem ipsum dolor sit amet, consectetur adipiscing elit.', array('width' => 100, 'fontSize' => 8, 'x' => 50, 'y' => 70));
$image->rectangle(40, 140, 170, 160, array(0, 0, 0), 0.5);
$image->textBox('Auto wrap and scale font size to multiline text box width and height bounds. Vestibulum venenatis risus scelerisque enim faucibus, ac pretium massa condimentum. Curabitur faucibus mi at convallis viverra. Integer nec finibus ligula, id hendrerit felis.', array('width' => 150, 'height' => 140, 'fontSize' => 16, 'x' => 50, 'y' => 150));
$image->show();
示例#2
0
 function init_old()
 {
     parent::init();
     $options = $this->options;
     // print_r($options);
     // exit;
     if ($options['bold'] and !$options['italic']) {
         if (file_exists(getcwd() . '/epan-components/xShop/templates/fonts/' . $options['font'] . '-Bold.ttf')) {
             $options['font'] = $options['font'] . '-Bold';
         }
         // else
         // $draw->setFontWeight(700);
     }
     if ($options['italic'] and !$options['bold']) {
         if (file_exists(getcwd() . '/epan-components/xShop/templates/fonts/' . $options['font'] . '-Italic.ttf')) {
             $options['font'] = $options['font'] . '-Italic';
         } else {
             $options['font'] = $options['font'] . '-Regular';
         }
     }
     if ($options['italic'] and $options['bold']) {
         if (file_exists(getcwd() . '/epan-components/xShop/templates/fonts/' . $options['font'] . '-BoldItalic.ttf')) {
             $options['font'] = $options['font'] . '-BoldItalic';
         } else {
             $options['font'] = $options['font'] . '-Regular';
         }
     }
     if (!$options['bold'] and !$options['italic']) {
         $options['font'] = $options['font'] . '-Regular';
     }
     $font_path = getcwd() . '/epan-components/xShop/templates/fonts/' . $options['font'] . '.ttf';
     // echo $font_path;
     $p = new \PHPImage($options['desired_width'], 10);
     $p->setFont($font_path);
     $p->setFontSize($options['font_size']);
     $p->textBox($options['text'], array('width' => $options['desired_width'], 'x' => 0, 'y' => 0));
     $size = $p->getTextBoxSize($options['font_size'], 0, $font_path, $p->last_text);
     $new_width = abs($size[0]) + abs($size[2]);
     // distance from left to right
     $new_height = abs($size[1]) + abs($size[5]);
     // distance from top to bottom
     $p1 = new \PHPImage($options['desired_width'], $new_height);
     $p1->setFont($font_path);
     $p1->setFontSize($options['font_size']);
     $p1->setTextColor($p1->hex2rgb($options['text_color']));
     // $p1->setAlignHorizontal('right');
     $p1->textBox($options['text'], array('width' => $new_width, 'x' => 0, 'y' => 0));
     if ($this->options['rotation_angle']) {
         $p1->xRotate($this->options['rotation_angle']);
         // $p1->rotate($this->options['rotation_angle']);
     }
     $this->phpimage = $p1;
     $this->new_height = $new_height;
 }