示例#1
0
文件: Imlib.php 项目: anvnguyen/Goteo
 /**
  * Adds text to the image.  Note that the angle should be one of the following
  * constants:  IMLIB_TEXT_TO_RIGHT, IMLIB_TEXT_TO_LEFT, IMLIB_TEXT_TO_DOWN,
  * IMLIB_TEXT_TO_UP, IMLIB_TEXT_TO_ANGLE
  *
  * @param   array   options     Array contains options
  *                              array(
  *                                  'text'  The string to draw
  *                                  'x'     Horizontal position
  *                                  'y'     Vertical Position
  *                                  'color' Font color
  *                                  'font'  Font to be used
  *                                  'size'  Size of the fonts in pixel
  *                                  'angle' A imlib direction constant
  *                              )
  *
  * @return TRUE or PEAR Error object on error
  * @see PEAR::isError()
  */
 function addText($params)
 {
     $default_params = array('text' => 'This is Text', 'x' => 10, 'y' => 20, 'color' => array(255, 0, 0), 'font' => 'Arial.ttf', 'size' => '12', 'angle' => IMLIB_TEXT_TO_RIGHT);
     $params = array_merge($default_params, $params);
     extract($params);
     if (!is_array($color)) {
         if ($color[0] == '#') {
             $color = $this->colorhex2colorarray($color);
         } else {
             include_once 'Image/Transform/Driver/ColorsDefs.php';
             $color = isset($colornames[$color]) ? $colornames[$color] : false;
         }
     }
     $fontResource = imlib_load_font($font . '/' . $size);
     imlib_text_draw($this->imageHandle, $fontResource, $x, $y, $text, $angle, $color[0], $color[1], $color[2], 255);
     return true;
 }
示例#2
0
    $text = 'php';
}
$font = '../../fonts/phpi.ttf';
$im = imlib_load_image('tshirt.png');
$w = imlib_image_get_width($im);
$h = imlib_image_get_height($im);
$im2 = imlib_load_image('blank.png');
$w2 = imlib_image_get_width($im2);
$h2 = imlib_image_get_height($im2);
$r = 110 / $w2;
$sh = $r * $h2;
imlib_image_modify_alpha($im, 255);
imlib_image_modify_alpha($im2, 150);
imlib_blend_image_onto_image($im, $im2, 1, 0, 0, $w2, $h2, 70, 70, 110, $sh, 0, 1, 1);
$fnt = imlib_load_font($font . "/{$si}");
imlib_get_text_size($fnt, $text, $dx, $dy, 0);
$x = 5 + $w / 2 - $dx / 2;
$y = 70 + $sh / 2 - $dy / 2;
// Fuzz-factor for all lowercase
if (strtolower($text) == $text) {
    $y -= 6;
}
imlib_text_draw($im, $fnt, $x + 2, $y + 2, $text, 0, 255, 255, 255, 220);
imlib_text_draw($im, $fnt, $x, $y + 2, $text, 0, 255, 255, 255, 220);
imlib_text_draw($im, $fnt, $x + 2, $y, $text, 0, 255, 255, 255, 220);
imlib_text_draw($im, $fnt, $x, $y, $text, 0, 255, 255, 255, 220);
imlib_text_draw($im, $fnt, $x + 1, $y + 1, $text, 0, 0, 0, 0, 220);
imlib_free_font($fnt);
$fnt2 = imlib_load_font($font . "/25");
imlib_text_draw($im, $fnt2, 10, $h - 40, "www.php.net", 0, 0, 0, 0, 65);
imlib_dump_image($im, $err, 90);