Exemplo n.º 1
20
function createEmailPic($jid, $email)
{
    $cachefile = DOCUMENT_ROOT . '/cache/' . $jid . '_email.png';
    if (file_exists(DOCUMENT_ROOT . '/cache/' . $jid . '_email.png')) {
        unlink(DOCUMENT_ROOT . '/cache/' . $jid . '_email.png');
    }
    $draw = new ImagickDraw();
    $draw->setFontSize(13);
    $draw->setGravity(Imagick::GRAVITY_CENTER);
    $canvas = new Imagick();
    $metrics = $canvas->queryFontMetrics($draw, $email);
    $canvas->newImage($metrics['textWidth'], $metrics['textHeight'], "transparent", "png");
    $canvas->annotateImage($draw, 0, 0, 0, $email);
    $canvas->setImageFormat('PNG');
    $canvas->writeImage($cachefile);
}
Exemplo n.º 2
0
function a0nCRQ($msg, $padx, $pady, $bc, $fc, $tc)
{
    $im = new Imagick();
    $idraw = new ImagickDraw();
    $idraw->setFontSize(30);
    $idraw->setFont('MyriadPro-Regular.otf');
    $idraw->setGravity(Imagick::GRAVITY_CENTER);
    $metrics = $im->queryFontMetrics($idraw, $msg);
    $im->newPseudoImage($metrics["textWidth"] + $padx * 2, $metrics["textHeight"] + $pady * 2, "xc:none");
    $idraw->setFillColor($fc);
    $idraw->setStrokeColor($bc);
    $idraw->roundrectangle(0, 0, $metrics["textWidth"] + $padx * 2 - 1, $metrics["textHeight"] + $pady * 2 - 1, 10, 10);
    $idraw->setFillColor($tc);
    $idraw->setStrokeColor($tc);
    $idraw->annotation(0, 0, $msg);
    $im->drawImage($idraw);
    return $im;
}
Exemplo n.º 3
0
Arquivo: Render.php Projeto: h3rb/page
function fl_text_render($_file, $id, $text, $fontname, $fontsize, $color = "#000000", $out_image_file_type = "png")
{
    $font = locate_font($fontname);
    if ($font === false) {
        fllog('fl_text_render: font `' . $fontname . '` not found at `' . flvault . $fontname . '`');
        return false;
    }
    $render = false;
    $out_image_file_type = strtolower($out_image_file_type);
    $cachefile = flcache . $id . '.' . $out_image_file_type;
    if ($_file !== false) {
        if (file1_is_older($cachefile, $_file)) {
            $render = true;
        }
    } else {
        $render = true;
    }
    if ($render === true) {
        try {
            $draw = new ImagickDraw();
            $draw->setFont($font);
            $draw->setFontSize(intval($fontsize));
            $draw->setGravity(Imagick::GRAVITY_CENTER);
            $draw->setFillColor($color);
            $canvas = new Imagick();
            $m = $canvas->queryFontMetrics($draw, htmlspecialchars_decode($text));
            $canvas->newImage($m['textWidth'], $m['textHeight'], "transparent", $out_image_file_type);
            $canvas->annotateImage($draw, 0, 0, 0, $text);
            $canvas->setImageFormat(strtoupper($out_image_file_type));
            $canvas->writeImage($cachefile);
            fllog('Writing to: ' . $cachefile);
            $canvas->clear();
            $canvas->destroy();
            $draw->clear();
            $draw->destroy();
        } catch (Exception $e) {
            fllog('fl_text_render() Error: ', $e->getMessage());
            return false;
        }
    }
    return $cachefile;
}
Exemplo n.º 4
0
function drawText(\Imagick $imagick, $shadow = false)
{
    $draw = new \ImagickDraw();
    if ($shadow == true) {
        $draw->setStrokeColor('black');
        $draw->setStrokeWidth(8);
        $draw->setFillColor('black');
    } else {
        $draw->setStrokeColor('none');
        $draw->setStrokeWidth(1);
        $draw->setFillColor('lightblue');
    }
    $draw->setFontSize(96);
    $text = "Imagick\nExample";
    $draw->setFont("../fonts/CANDY.TTF");
    $draw->setGravity(\Imagick::GRAVITY_SOUTHWEST);
    $imagick->annotateimage($draw, 40, 40, 0, $text);
    if ($shadow == true) {
        $imagick->blurImage(10, 5);
    }
    return $imagick;
}
Exemplo n.º 5
0
 /**
  * Draws a text string on the image in a specified location, with
  * the specified style information.
  *
  * @TODO: Need to differentiate between the stroke (border) and the fill color,
  *        but this is a BC break, since we were just not providing a border.
  *
  * @param string  $text       The text to draw.
  * @param integer $x          The left x coordinate of the start of the text string.
  * @param integer $y          The top y coordinate of the start of the text string.
  * @param string  $font       The font identifier you want to use for the text.
  * @param string  $color      The color that you want the text displayed in.
  * @param integer $direction  An integer that specifies the orientation of the text.
  * @param string  $fontsize   Size of the font (small, medium, large, giant)
  */
 public function text($string, $x, $y, $font = '', $color = 'black', $direction = 0, $fontsize = 'small')
 {
     $fontsize = Horde_Image::getFontSize($fontsize);
     $pixel = new ImagickPixel($color);
     $draw = new ImagickDraw();
     $draw->setFillColor($pixel);
     if (!empty($font)) {
         $draw->setFont($font);
     }
     $draw->setFontSize($fontsize);
     $draw->setGravity(Imagick::GRAVITY_NORTHWEST);
     try {
         $res = $this->_imagick->annotateImage($draw, $x, $y, $direction, $string);
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
     $draw->destroy();
 }
Exemplo n.º 6
0
}
$img_path = "images" . DIRECTORY_SEPARATOR;
$img_fullname = $img_path . $img_name;
$image = new Imagick($img_fullname);
scale_image($img_p, $height, $width, $image);
if (array_key_exists('text', $_GET)) {
    $text = $_GET['text'];
    $text = preg_replace('/\\|/i', "\n", $text);
    $pointsize = max(min($width / strlen($text) * 1.2, $height * 0.2), 5);
    $font = "mplus-1c-medium.ttf";
    $draw = new ImagickDraw();
    $draw->setFillColor(new ImagickPixel("#" . $foreground->get_hex()));
    $draw->setFont($font);
    $draw->setFontSize($pointsize);
    $draw->setTextUnderColor(new ImagickPixel("#" . $background->get_hex()));
    $draw->setGravity(imagick::GRAVITY_SOUTH);
    $image->annotateImage($draw, 0, 0, 0, $text);
}
$image->setFilename("puppy");
$output = $image->getimageblob();
$outputtype = $image->getFormat();
header("Content-type: {$outputtype}");
echo $output;
function scale_image($img_p, $height, $width, $image)
{
    if ($img_p > 1) {
        $tmp_w = $height * $img_p;
        $tmp_h = $height;
    } else {
        $tmp_w = $width;
        $tmp_h = $width / $img_p;
Exemplo n.º 7
0
 /**
  * 加给图片加水印
  *
  * @param strimg $groundImage 要加水印地址
  * @param int $waterPos 水印位置
  * @param string $waterImage 水印图片地址
  * @param string $waterText 文本文字
  * @param int $textFont 文字大小
  * @param string $textColor 文字颜色
  * @param int $minWidth 小于此值不加水印
  * @param int $minHeight 小于此值不加水印
  * @param float $alpha 透明度
  * @return FALSE
  */
 public static function waterMark($groundImage, $waterPos = 0, $waterImage = "", $waterText = "", $textFont = 15, $textColor = "#FF0000", $minWidth = '100', $minHeight = '100', $alpha = 0.9)
 {
     $isWaterImg = FALSE;
     $bg_h = $bg_w = $water_h = $water_w = 0;
     //获取背景图的高,宽
     if (is_file($groundImage) && !empty($groundImage)) {
         $bg = new Imagick();
         $bg->readImage($groundImage);
         $bg_h = $bg->getImageHeight();
         $bg_w = $bg->getImageWidth();
     }
     //获取水印图的高,宽
     if (is_file($waterImage) && !empty($waterImage)) {
         $water = new Imagick($waterImage);
         $water_h = $water->getImageHeight();
         $water_w = $water->getImageWidth();
     }
     //如果背景图的高宽小于水印图的高宽或指定的高和宽则不加水印
     if ($bg_h < $minHeight || $bg_w < $minWidth || $bg_h < $water_h || $bg_w < $water_w) {
         return;
     } else {
         $isWaterImg = TRUE;
     }
     //加水印
     if ($isWaterImg) {
         $dw = new ImagickDraw();
         //加图片水印
         if (is_file($waterImage)) {
             $water->setImageOpacity($alpha);
             $dw->setGravity($waterPos);
             $dw->composite($water->getImageCompose(), 0, 0, 50, 0, $water);
             $bg->drawImage($dw);
             if (!$bg->writeImage($groundImage)) {
                 return FALSE;
             }
         } else {
             //加文字水印
             $dw->setFontSize($textFont);
             $dw->setFillColor($textColor);
             $dw->setGravity($waterPos);
             $dw->setFillAlpha($alpha);
             $dw->annotation(0, 0, $waterText);
             $bg->drawImage($dw);
             if (!$bg->writeImage($groundImage)) {
                 return FALSE;
             }
         }
     }
 }
Exemplo n.º 8
0
$runningHt = 15;
for ($i = count($legends) - 1; $i >= 0; $i--) {
    $p = explode("\n", $titles[$i]);
    $draw = new ImagickDraw();
    $draw->setFont('Helvetica');
    $draw->setFontSize(12);
    $draw->annotation(5, $runningHt, $titles[$i]);
    $canvas->drawImage($draw);
    $canvas->compositeImage($legends[$i], imagick::COMPOSITE_OVER, 0, $runningHt + 12 * (count($p) - 1));
    $runningHt += $legends[$i]->getImageHeight() + 20 + 12 * (count($p) - 1);
}
$canvas->writeImage($tmp_dir . $id . '.legend.png');
// title
$canvas = new Imagick();
$canvas->newImage($w, 30, new ImagickPixel('white'));
$canvas->setImageFormat('png');
$draw = new ImagickDraw();
$draw->setFont('Helvetica');
$draw->setFontSize(18);
$draw->setGravity(imagick::GRAVITY_CENTER);
$draw->annotation(0, 0, $_REQUEST['title']);
$canvas->drawImage($draw);
$canvas->writeImage($tmp_dir . $id . '.title.png');
function mkLegendUrl($u)
{
    return preg_replace('/&(STYLES|SRS)[^&]+/', '', $u);
}
$handle = fopen($tmp_dir . $id . '.html', 'w');
fwrite($handle, "<html><head><title>" . $_REQUEST['title'] . "</title><style>td {vertical-align : top} img {border : 1px solid gray}</style></head><body><table><tr><td><img src='{$tmp_url}{$id}.title.png'></td></tr><tr><td><img src='{$tmp_url}{$id}.png'></td><td><img src='{$tmp_url}{$id}.legend.png'></td></tr></table></body></html>");
fclose($handle);
echo json_encode(array('html' => "{$tmp_url}{$id}.html", 'map' => "{$tmp_url}{$id}.png", 'legend' => "{$tmp_url}{$id}.legend.png"));
Exemplo n.º 9
0
function fl_regenerate_sprite_cache($sheet_id, $sprites, $out_image_file_type = "png")
{
    if (defined('fl_test_environment')) {
        fllog('! fl_regenerate_sprite_cache: ' . flcache . $sheet_id . '.' . $out_image_file_type);
    }
    $biggest_w = 0;
    $biggest_h = 0;
    $rects = array();
    $i = 0;
    foreach ($sprites as &$sprite) {
        $i++;
        //var_dump( $sprite );
        if (!isset($sprite['size'])) {
            $sprite['size'] = 14;
        }
        if (!isset($sprite['color'])) {
            $sprite['color'] = '#000000';
        }
        if (!isset($sprite['font'])) {
            fllog('Font not set for sprite id `' . $sheet_id . '` sprite #' . $i);
            continue;
        }
        //var_dump($sprite);
        $sprite['dimension'] = fl_query_font_render_size(flres(flvault . $sprite['font']), intval($sprite['size']), $sprite['color'], $sprite['text']);
        $sprite['w'] = $sprite['dimension']['w'];
        $sprite['h'] = $sprite['dimension']['h'];
        $w = intval($sprite['w']);
        $h = intval($sprite['h']);
        if ($w > $biggest_w) {
            $biggest_w = $w;
        }
        if ($h > $biggest_h) {
            $biggest_h = $h;
        }
        $rects[$i - 1] = $sprite;
    }
    // echo 'Packing rects..';
    $packed = PackRect($rects, fl_biggest_w, fl_biggest_h, $w, $h, fl_pack_precision, fl_pack_precision);
    $i = 0;
    try {
        $total = count($rects);
        $c = new Imagick();
        //var_dump($packed);
        $c->newImage(intval($packed['width']), intval($packed['height']), "transparent", $out_image_file_type);
        $css = '';
        $d = array();
        foreach ($packed as $k => $sprite) {
            if (!is_numeric($k)) {
                continue;
            } else {
                $d = new ImagickDraw();
                $d->setFont(fl_get_fontfile($sprite['font']));
                $d->setFontSize(floatval($sprite['size']));
                $d->setGravity(Imagick::GRAVITY_NORTHWEST);
                $d->setFillColor($sprite['color']);
                $result = $c->annotateImage($d, floatval($sprite['x']), floatval($sprite['y']), 0, $sprite['text']);
                $d->clear();
                $d->destroy();
            }
        }
        $c->setImageFormat(strtoupper($out_image_file_type));
        $c->writeImage(flres(flcache . $sheet_id . '.' . $out_image_file_type));
        $c->clear();
        $c->destroy();
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    fl_make_sheet($sheet_id, $packed, $out_image_file_type);
    //die;
}
Exemplo n.º 10
0
<?php

// Create objects
$image = new Imagick('../files/images/userbar_old.png');
// Watermark text
// Create a new drawing palette
$draw = new ImagickDraw();
// Set font properties
$draw->setFont('../files/fonts/visitor.ttf');
$draw->setFontSize(10);
$draw->setFillColor('white');
$text = "";
if (isset($_GET['user'])) {
    $text = $_GET['user'];
}
// Position text at the bottom-right of the image
$draw->setGravity(Imagick::GRAVITY_EAST);
$image->annotateImage($draw, 8, 0, 0, $text);
// Set output image format
$image->setImageFormat('png');
// Output the new image
header('Content-type: image/png');
echo $image;
Exemplo n.º 11
0
 public function diyAction()
 {
     Yaf_Dispatcher::getInstance()->autoRender(FALSE);
     $id = $this->_req->getQuery('id', 1);
     if ($this->_req->isPost()) {
         $this->diy = new DiyModel();
         $pre_svg = '<?xml version="1.0" standalone="no" ?>' . trim($_POST['svg_val']);
         $rdate = APPLICATION_PATH . '/public/Uploads/' . date("Ymd", time());
         //文件名
         if (!file_exists($rdate)) {
             chmod(APPLICATION_PATH . '/public/Uploads/', 0777);
             mkdir($rdate);
             //创建目录
         }
         $savename = $this->create_unique();
         $path = $rdate . '/' . $savename;
         if (!($file_svg = fopen($path . '.svg', 'w+'))) {
             echo "不能打开文件 {$path}.'.svg'";
             exit;
         }
         if (fwrite($file_svg, $pre_svg) === FALSE) {
             echo "不能写入到文件 {$path}.'.svg'";
             exit;
         }
         echo "已成功写入";
         fclose($file_svg);
         //$path= APPLICATION_PATH . '/public/Uploads/' . date("Ymd", time()) .'/m-1';
         //添加图片转化
         $im = new Imagick();
         $im->setBackgroundColor(new ImagickPixel('transparent'));
         $svg = file_get_contents($path . '.svg');
         $im->readImageBlob($svg);
         $im->setImageFormat("png");
         $am = $im->writeImage($path . '.png');
         $im->thumbnailImage(579, 660, true);
         /* 改变大小 */
         $ams = $im->writeImage($path . '-t.png');
         $im->clear();
         $im->destroy();
         //图片加水印
         $waterpath = APPLICATION_PATH . '/public/source/source.png';
         $im1 = new Imagick($waterpath);
         $im2 = new Imagick($path . '.png');
         $im2->thumbnailImage(600, 600, true);
         $dw = new ImagickDraw();
         $dw->setGravity(5);
         $dw->setFillOpacity(0.1);
         $dw->composite($im2->getImageCompose(), 0, 0, 50, 0, $im2);
         $im1->drawImage($dw);
         if (!$im1->writeImage($path . '-s.png')) {
             echo '加水印失败';
             exit;
         }
         $im1->clear();
         $im2->clear();
         $im1->destroy();
         $im2->destroy();
         //exit;
         //删除相应的文件
         //unlink($path.'.svg');
         //unlink($path.'.png');
         $filepath = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '.png';
         $data['origin_img'] = $filepath;
         $data['diy_synthetic_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '-s.png';
         $data['diy_preview_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '-s.png';
         $data['user_id'] = 0;
         $data['source'] = 3;
         $data['created'] = date("Y-m-d H:i:s", time());
         $datas['image'] = $data['diy_synthetic_img'];
         $datas['user_id'] = 0;
         $datas['source'] = 2;
         $datas['state'] = 1;
         $datas['createtime'] = date("Y-m-d H:i:s", time());
         $datas['updatetime'] = date("Y-m-d H:i:s", time());
         $diy_picture_id = $this->diy->adddiy($data);
         //$datas['use'] = $tool;
         //$datas['author'] = $userinfo['mobile'];
         $this->userpicture = new UserpictureModel();
         $datas['diy_picture_id'] = $diy_picture_id;
         $this->userpicture->adduserpicture($datas);
         $response_data['origin_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '.png';
         $response_data['diy_preview_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '-s.png';
         $response_data['diy_thumb_img'] = '/Uploads/' . date("Ymd", time()) . '/' . $savename . '-t.png';
         $response_data['diy_picture_id'] = $diy_picture_id;
         //$this->getView()->display("/index/buy.html",$response_data);
         $this->_session->set('diypicture', $response_data);
         $this->_redis = new phpredis();
         $this->_redis->set($diy_picture_id, json_encode($response_data));
         header("Location:/index/share?diy=" . $diy_picture_id);
     } else {
         switch ($id) {
             case 1:
                 $this->getView()->display("index/diy_1.html");
                 break;
             case 2:
                 $this->getView()->display("index/diy_2.html");
                 break;
             case 3:
                 $this->getView()->display("index/diy_3.html");
                 break;
             case 4:
                 $this->getView()->display("index/diy_4.html");
                 break;
             case 5:
                 $this->getView()->display("index/diy_5.html");
                 break;
             case 6:
                 $this->getView()->display("index/diy_6.html");
                 break;
             case 7:
                 $this->getView()->display("index/diy_7.html");
                 break;
         }
     }
 }
Exemplo n.º 12
0
/**
 * imagick watermarking
 *
 * @param string $filename
 * @return bool
 */
function tp_imagick_watermark($filename)
{
    $watermark_text = elgg_get_plugin_setting('watermark_text', 'tidypics');
    if (!$watermark_text) {
        return false;
    }
    // plugins can do their own watermark and return false to prevent this function from running
    if (elgg_trigger_plugin_hook('tp_watermark', 'imagick', $filename, true) === false) {
        return true;
    }
    $owner = elgg_get_logged_in_user_entity();
    $watermark_text = tp_process_watermark_text($watermark_text, $owner);
    $img = new Imagick($filename);
    $img->readImage($image);
    $draw = new ImagickDraw();
    //$draw->setFont("");
    $draw->setFontSize(28);
    $draw->setFillOpacity(0.5);
    $draw->setGravity(Imagick::GRAVITY_SOUTH);
    $img->annotateImage($draw, 0, 0, 0, $watermark_text);
    if ($img->writeImage($filename) != true) {
        $img->destroy();
        return false;
    }
    $img->destroy();
    return true;
}
Exemplo n.º 13
0
 /**
  * {@inheritDoc}
  */
 public function watermarkText($wm_txt_text, $wm_txt_font_path, $wm_txt_start_x = 0, $wm_txt_start_y = 0, $wm_txt_font_size = 10, $wm_txt_font_color = 'transwhitetext', $wm_txt_font_alpha = 60)
 {
     if (false === $this->isClassSetup()) {
         return false;
     }
     // setup source image object
     if (false === $this->setupSourceImageObject()) {
         return false;
     }
     // check previous step contain errors?
     if ($this->isPreviousError() === true) {
         return false;
     }
     if (!is_file($wm_txt_font_path)) {
         $this->status = false;
         $this->status_msg = 'Unable to load font file.';
         return false;
     }
     $wm_txt_font_path = realpath($wm_txt_font_path);
     // find text width and height
     // +10 will be -5 padding on watermark text area.
     $ImagickDraw = new \ImagickDraw();
     $ImagickDraw->setFont($wm_txt_font_path);
     $ImagickDraw->setFontSize($wm_txt_font_size);
     $ImagickDraw->setGravity(\Imagick::GRAVITY_NORTHWEST);
     // set new resolution for font due to it is smaller than GD if it was not set.
     $ImagickDraw->setresolution(96, 96);
     $type_space = $this->Imagick->queryFontMetrics($ImagickDraw, $wm_txt_text, false);
     if (is_array($type_space) && array_key_exists('textWidth', $type_space) && array_key_exists('textHeight', $type_space)) {
         $wm_txt_height = $type_space['textHeight'];
         $wm_txt_width = $type_space['textWidth'];
     }
     unset($type_space);
     // if start x or y is number, convert to integer value
     if (is_numeric($wm_txt_start_x)) {
         $wm_txt_start_x = intval($wm_txt_start_x);
     }
     if (is_numeric($wm_txt_start_y)) {
         $wm_txt_start_y = intval($wm_txt_start_y);
     }
     // if start x or y is NOT number, find the real position of start x or y from word left, center, right, top, middle, bottom
     if (!is_numeric($wm_txt_start_x) || !is_numeric($wm_txt_start_y)) {
         if (!is_numeric($wm_txt_start_x)) {
             switch (strtolower($wm_txt_start_x)) {
                 case 'center':
                     $image_width = $this->Imagick->getImageWidth();
                     $watermark_width = $wm_txt_width;
                     $wm_txt_start_x = $this->calculateStartXOfCenter($watermark_width, $image_width);
                     unset($image_width, $watermark_width);
                     break;
                 case 'right':
                     $image_width = $this->Imagick->getImageWidth();
                     $wm_txt_start_x = intval($image_width - $wm_txt_width) - 5;
                     // minus 5 because Imagick is different from GD.
                     unset($image_width);
                     break;
                 case 'left':
                 default:
                     $wm_txt_start_x = 10;
                     // Imagick is different from GD, so increase it.
                     break;
             }
         }
         if (!is_numeric($wm_txt_start_y)) {
             switch (strtolower($wm_txt_start_y)) {
                 case 'middle':
                     $image_height = $this->Imagick->getImageHeight();
                     $watermark_height = $wm_txt_height;
                     $wm_txt_start_y = $this->calculateStartXOfCenter($watermark_height, $image_height);
                     unset($image_height, $watermark_height);
                     break;
                 case 'bottom':
                     $image_height = $this->Imagick->getImageHeight();
                     if ($image_height - ($wm_txt_height + 5) > '0') {
                         $wm_txt_start_y = intval($image_height - ($wm_txt_height + 5));
                     } else {
                         $wm_txt_start_y = intval($image_height - $wm_txt_height);
                     }
                     unset($image_height);
                     break;
                 case 'top':
                 default:
                     $wm_txt_start_y = 10;
                     // Imagick is different from GD, so increase it.
                     break;
             }
         }
     }
     // begins watermark text --------------------------------------------------------------------------------------------
     // set color
     $black = new \ImagickPixel('black');
     $white = new \ImagickPixel('white');
     $transwhite = new \ImagickPixel('rgba(255, 255, 255, 0)');
     // set color transparent white
     $transwhitetext = new \ImagickPixel('rgba(255, 255, 255, ' . $this->convertAlpha127ToRgba($wm_txt_font_alpha) . ')');
     if (!isset(${$wm_txt_font_color})) {
         $wm_txt_font_color = 'transwhitetext';
     }
     // fill font color
     $ImagickDraw->setFillColor(${$wm_txt_font_color});
     // write text on image
     if ($this->source_image_frames > 1) {
         // if source image is animated gif
         $this->Imagick = $this->Imagick->coalesceImages();
         if (is_object($this->Imagick)) {
             $i = 1;
             foreach ($this->Imagick as $Frame) {
                 $Frame->annotateImage($ImagickDraw, $wm_txt_start_x, $wm_txt_start_y, 0, $wm_txt_text);
                 $Frame->setImagePage(0, 0, 0, 0);
                 if ($i == 1) {
                     $this->ImagickFirstFrame = $Frame->getImage();
                 }
                 $i++;
             }
             unset($Frame, $i);
         }
     } else {
         $this->Imagick->annotateImage($ImagickDraw, $wm_txt_start_x, $wm_txt_start_y, 0, $wm_txt_text);
         if ($this->source_image_type == '1') {
             // if source image is gif, set image page to prevent sizing error.
             $this->Imagick->setImagePage(0, 0, 0, 0);
         }
         $this->ImagickFirstFrame = null;
     }
     // end watermark text -----------------------------------------------------------------------------------------------
     $ImagickDraw->clear();
     $black->destroy();
     $transwhite->destroy();
     $transwhitetext->destroy();
     $white->destroy();
     unset($black, $ImagickDraw, $transwhite, $transwhitetext, $white, $wm_txt_height, $wm_txt_width);
     $this->destination_image_height = $this->Imagick->getImageHeight();
     $this->destination_image_width = $this->Imagick->getImageWidth();
     $this->source_image_height = $this->destination_image_height;
     $this->source_image_width = $this->destination_image_width;
     $this->status = true;
     $this->status_msg = null;
     return true;
 }
Exemplo n.º 14
0
function setGravity($fillColor, $strokeColor, $backgroundColor)
{
    $draw = new \ImagickDraw();
    $draw->setStrokeColor($strokeColor);
    $draw->setFillColor($fillColor);
    $draw->setStrokeWidth(1);
    $draw->setFontSize(24);
    $gravitySettings = array(\Imagick::GRAVITY_NORTHWEST => 'NorthWest', \Imagick::GRAVITY_NORTH => 'North', \Imagick::GRAVITY_NORTHEAST => 'NorthEast', \Imagick::GRAVITY_WEST => 'West', \Imagick::GRAVITY_CENTER => 'Centre', \Imagick::GRAVITY_SOUTHWEST => 'SouthWest', \Imagick::GRAVITY_SOUTH => 'South', \Imagick::GRAVITY_SOUTHEAST => 'SouthEast', \Imagick::GRAVITY_EAST => 'East');
    $draw->setFont("../fonts/Arial.ttf");
    foreach ($gravitySettings as $type => $description) {
        $draw->setGravity($type);
        $draw->annotation(50, 50, '"' . $description . '"');
    }
    $imagick = new \Imagick();
    $imagick->newImage(500, 500, $backgroundColor);
    $imagick->setImageFormat("png");
    $imagick->drawImage($draw);
    header("Content-Type: image/png");
    echo $imagick->getImageBlob();
}
Exemplo n.º 15
0
function fl_query_font_render_size($font, $size, $color, $text)
{
    // echo 'Querying for '.$text;
    $d = new ImagickDraw();
    $d->setFont($font);
    $d->setFontSize(intval($size));
    $d->setGravity(Imagick::GRAVITY_CENTER);
    $d->setFillColor($color);
    $c = new Imagick();
    $m = $c->queryFontMetrics($d, $text);
    $c->clear();
    $c->destroy();
    $d->clear();
    $d->destroy();
    $dim = array('w' => $m['textWidth'], 'h' => $m['textHeight']);
    return $dim;
}
Exemplo n.º 16
0
<?php

/*
	Simple example of watermarking
*/
/* Create Imagick object */
$Imagick = new Imagick();
/* Create a drawing object and set the font size */
$ImagickDraw = new ImagickDraw();
$ImagickDraw->setFontSize(50);
/* Read image into object*/
$Imagick->readImage('/tmp/test.jpg');
/* Seek the place for the text */
$ImagickDraw->setGravity(Imagick::GRAVITY_CENTER);
/* Write the text on the image */
$Imagick->annotateImage($ImagickDraw, 4, 20, 0, "Test Watermark");
/* Set format to png */
$Imagick->setImageFormat('png');
/* Output */
header("Content-Type: image/{$Imagick->getImageFormat()}");
echo $Imagick->getImageBlob();
Exemplo n.º 17
0
 /**
  * @param string $code
  * @param int    $width
  * @param int    $height
  *
  * @return \ManaPHP\Http\ResponseInterface
  */
 protected function _generateByImagic($code, $width, $height)
 {
     $image = new \Imagick();
     $draw = new \ImagickDraw();
     $image->newImage($width, $height, new \ImagickPixel('rgb(' . $this->_bgRGB . ')'));
     $draw->setFont($this->alias->resolve($this->_fonts[(int) (mt_rand() % count($this->_fonts))]));
     $draw->setGravity(\Imagick::GRAVITY_NORTHWEST);
     $referenceFontSize = min($height, $width / $this->_length);
     $x = mt_rand($referenceFontSize * 0.1, $referenceFontSize * 0.3);
     $length = strlen($code);
     $fgPixel = new \ImagickPixel();
     /** @noinspection ForeachInvariantsInspection */
     for ($i = 0; $i < $length; $i++) {
         $fontSize = $referenceFontSize * mt_rand(800, 1000) / 1000;
         $draw->setFontSize($fontSize);
         $fgPixel->setColor('rgb(' . mt_rand(0, 240) . ',' . mt_rand(0, 240) . ',' . mt_rand(0, 240) . ')');
         $draw->setFillColor($fgPixel);
         $angle = mt_rand(-$this->_angleAmplitude, $this->_angleAmplitude);
         $y = ($height - $referenceFontSize) * mt_rand(-1000, 1000) / 1000;
         $image->annotateImage($draw, $x, $y, $angle, $code[$i]);
         $x += $fontSize * mt_rand(600, 800) / 1000;
         for ($k = 0; $k < $this->_noiseCharCount; $k++) {
             $letter = $this->_charset[(int) (mt_rand() % strlen($this->_charset))];
             $fgPixel->setColor('rgb(' . mt_rand(0, 240) . ',' . mt_rand(0, 240) . ',' . mt_rand(0, 240) . ')');
             $draw->setFillColor($fgPixel);
             $draw->setFontSize($fontSize * 0.4 * $this->_rand_amplitude(0.1));
             $angle = mt_rand(-40, 40);
             $image->annotateImage($draw, $x + mt_rand(-700, 700) / 1000 * $fontSize, $fontSize / 2 + mt_rand(-$fontSize * 0.5, $fontSize * 0.5), $angle, $letter);
         }
     }
     $this->response->setContentType('image/jpeg');
     $image->setImageFormat('jpeg');
     $this->response->setContent((string) $image);
     $image->destroy();
     $fgPixel->destroy();
     $draw->destroy();
     return $this->response;
 }
Exemplo n.º 18
0
 public function generate_book_front_thumbnail($cover_img = '', $book_name = '', $book_author = '', $width = 196, $height = 144)
 {
     $book_template = $this->config->item('book_template');
     $im = new Imagick($book_template);
     $im->setImageBackgroundColor('white');
     $im = $im->flattenImages();
     $im->scaleImage($width, $height);
     //echo $cover_img;
     if (strlen($cover_img) > 0) {
         // Open the watermark
         $watermark = new Imagick();
         $watermark->readImage($cover_img);
         //echo "cover_img: $cover_img";
         // how big are the images?
         $iWidth = $im->getImageWidth();
         $iHeight = $im->getImageHeight();
         //let check if we need to scale the book cover image to position it in the book template properly
         $watermark_sizes = $this->scale_watermark($watermark, $iHeight, $iWidth);
         $wHeight = $watermark_sizes['height'];
         $wWidth = $watermark_sizes['width'];
         // calculate the position
         $x = $iWidth / 2 - $wWidth / 2;
         $y = $iHeight / 2 - $wHeight / 2;
         $watermark->scaleImage($wWidth, $wHeight);
         // Overlay the watermark on the original image
         $im->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);
     }
     /* Create a drawing object and set the font size */
     $text_watermark = new Imagick();
     $draw = new ImagickDraw();
     /*** set the font size ***/
     // Set font properties
     //$draw->setFont('Arial');
     $draw->setFontSize(20);
     //$draw->setFillColor('black');
     //annovate with book name
     $draw->setGravity(Imagick::GRAVITY_NORTH);
     $im->annotateImage($draw, 0, 0, 0, $book_name);
     //annotate with book author
     $draw->setGravity(Imagick::GRAVITY_SOUTH);
     $im->annotateImage($draw, 0, 0, 0, $book_author);
     //$im->compositeImage($text_watermark, imagick::COMPOSITE_OVER, 0, 0);
     $im->thumbnailImage($width, $height);
     /**** set to png ***/
     $im->setImageFormat("png");
     return $im;
 }
Exemplo n.º 19
0
 public function transform($operation, $parameters)
 {
     if ($this->properties["mimetype"] == "image/tilepic") {
         return false;
     }
     # no transformations for Tilepic
     if (!$this->handle) {
         return false;
     }
     if (!$this->info["TRANSFORMATIONS"][$operation]) {
         # invalid transformation
         $this->postError(1655, _t("Invalid transformation %1", $operation), "WLPlugImagick->transform()");
         return false;
     }
     # get parameters for this operation
     $sparams = $this->info["TRANSFORMATIONS"][$operation];
     $w = $parameters["width"];
     $h = $parameters["height"];
     $cw = $this->get("width");
     $ch = $this->get("height");
     if ((bool) $this->properties['no_upsampling']) {
         $w = min($cw, round($w));
         $h = min($ch, round($h));
     }
     $do_crop = 0;
     try {
         switch ($operation) {
             # -----------------------
             case 'ANNOTATE':
                 $d = new ImagickDraw();
                 if ($parameters['font']) {
                     $d->setFont($parameters['font']);
                 }
                 $size = $parameters['size'] > 0 ? $parameters['size'] : 18;
                 $d->setFontSize($size);
                 $inset = $parameters['inset'] > 0 ? $parameters['inset'] : 0;
                 $pw = new ImagickPixel();
                 $pw->setColor($parameters['color'] ? $parameters['color'] : "black");
                 $d->setFillColor($pw);
                 switch ($parameters['position']) {
                     case 'north_east':
                         $d->setGravity(imagick::GRAVITY_NORTHEAST);
                         break;
                     case 'north_west':
                         $d->setGravity(imagick::GRAVITY_NORTHWEST);
                         break;
                     case 'north':
                         $d->setGravity(imagick::GRAVITY_NORTH);
                         break;
                     case 'south_east':
                         $d->setGravity(imagick::GRAVITY_SOUTHEAST);
                         break;
                     case 'south':
                         $d->setGravity(imagick::GRAVITY_SOUTH);
                         break;
                     case 'center':
                         $d->setGravity(imagick::GRAVITY_CENTER);
                         break;
                     case 'south_west':
                     default:
                         $d->setGravity(imagick::GRAVITY_SOUTHWEST);
                         break;
                 }
                 $this->handle->annotateImage($d, $inset, $size + $inset, 0, $parameters['text']);
                 break;
                 # -----------------------
             # -----------------------
             case 'WATERMARK':
                 if (!file_exists($parameters['image'])) {
                     break;
                 }
                 $vn_opacity_setting = $parameters['opacity'];
                 if ($vn_opacity_setting < 0 || $vn_opacity_setting > 1) {
                     $vn_opacity_setting = 0.5;
                 }
                 $d = new ImagickDraw();
                 if (($vn_watermark_width = $parameters['width']) < 10) {
                     $vn_watermark_width = $cw / 2;
                 }
                 if (($vn_watermark_height = $parameters['height']) < 10) {
                     $vn_watermark_height = $ch / 2;
                 }
                 switch ($parameters['position']) {
                     case 'north_east':
                         $vn_watermark_x = $cw - $vn_watermark_width;
                         $vn_watermark_y = 0;
                         break;
                     case 'north_west':
                         $vn_watermark_x = 0;
                         $vn_watermark_y = 0;
                         break;
                     case 'north':
                         $vn_watermark_x = ($cw - $vn_watermark_width) / 2;
                         $vn_watermark_y = 0;
                         break;
                     case 'south_east':
                         $vn_watermark_x = $cw - $vn_watermark_width;
                         $vn_watermark_y = $ch - $vn_watermark_height;
                         break;
                     case 'south':
                         $vn_watermark_x = ($cw - $vn_watermark_width) / 2;
                         $vn_watermark_y = $ch - $vn_watermark_height;
                         break;
                     case 'center':
                         $vn_watermark_x = ($cw - $vn_watermark_width) / 2;
                         $vn_watermark_y = ($ch - $vn_watermark_height) / 2;
                         break;
                     case 'south_west':
                     default:
                         $vn_watermark_x = $cw - $vn_watermark_width;
                         $vn_watermark_y = $ch - $vn_watermark_height;
                         break;
                 }
                 $w = new Imagick();
                 if (!$w->readImage($parameters['image'])) {
                     $this->postError(1610, _t("Couldn't load watermark image at %1", $parameters['image']), "WLPlugImagick->transform:WATERMARK()");
                     return false;
                 }
                 //$w->evaluateImage(imagick::COMPOSITE_MINUS, $vn_opacity, imagick::CHANNEL_OPACITY) ; [seems broken with latest imagick circa March 2010?]
                 if (method_exists($w, "setImageOpacity")) {
                     // added in ImageMagick 6.3.1
                     $w->setImageOpacity($vn_opacity_setting);
                 }
                 $d->composite(imagick::COMPOSITE_DISSOLVE, $vn_watermark_x, $vn_watermark_y, $vn_watermark_width, $vn_watermark_height, $w);
                 $this->handle->drawImage($d);
                 break;
                 # -----------------------
             # -----------------------
             case 'SCALE':
                 $aa = $parameters["antialiasing"];
                 if ($aa <= 0) {
                     $aa = 0;
                 }
                 switch ($parameters["mode"]) {
                     # ----------------
                     case "width":
                         $scale_factor = $w / $cw;
                         $h = $ch * $scale_factor;
                         break;
                         # ----------------
                     # ----------------
                     case "height":
                         $scale_factor = $h / $ch;
                         $w = $cw * $scale_factor;
                         break;
                         # ----------------
                     # ----------------
                     case "bounding_box":
                         $scale_factor_w = $w / $cw;
                         $scale_factor_h = $h / $ch;
                         $w = $cw * ($scale_factor_w < $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         $h = $ch * ($scale_factor_w < $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         break;
                         # ----------------
                     # ----------------
                     case "fill_box":
                         $crop_from = $parameters["crop_from"];
                         if (!in_array($crop_from, array('center', 'north_east', 'north_west', 'south_east', 'south_west', 'random'))) {
                             $crop_from = '';
                         }
                         $scale_factor_w = $w / $cw;
                         $scale_factor_h = $h / $ch;
                         $w = $cw * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         $h = $ch * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         $do_fill_box_crop = true;
                         break;
                         # ----------------
                 }
                 $w = round($w);
                 $h = round($h);
                 if ($w > 0 && $h > 0) {
                     $crop_w_edge = $crop_h_edge = 0;
                     if (preg_match("/^([\\d]+)%\$/", $parameters["trim_edges"], $va_matches)) {
                         $crop_w_edge = ceil(intval($va_matches[1]) / 100 * $w);
                         $crop_h_edge = ceil(intval($va_matches[1]) / 100 * $h);
                     } else {
                         if (isset($parameters["trim_edges"]) && intval($parameters["trim_edges"]) > 0) {
                             $crop_w_edge = $crop_h_edge = intval($parameters["trim_edges"]);
                         }
                     }
                     if (!$this->handle->resizeImage($w + $crop_w_edge * 2, $h + $crop_h_edge * 2, imagick::FILTER_CUBIC, $aa)) {
                         $this->postError(1610, _t("Error during resize operation"), "WLPlugImagick->transform()");
                         return false;
                     }
                     if ($do_fill_box_crop) {
                         // use face detection info to intelligently crop
                         if (is_array($this->properties['faces']) && sizeof($this->properties['faces'])) {
                             $va_info = array_shift($this->properties['faces']);
                             $crop_from_offset_x = ceil($va_info['x'] * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h));
                             $crop_from_offset_x -= ceil(0.15 * $parameters["width"]);
                             // since face will be tightly cropped give it some room
                             $crop_from_offset_y = ceil($va_info['y'] * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h));
                             $crop_from_offset_y -= ceil(0.15 * $parameters["height"]);
                             // since face will be tightly cropped give it some room
                             // Don't try to crop beyond image boundaries, you just end up scaling the image, often awkwardly
                             if ($crop_from_offset_x > $w - $parameters["width"]) {
                                 $crop_from_offset_x = 0;
                             }
                             if ($crop_from_offset_y > $h - $parameters["height"]) {
                                 $crop_from_offset_y = 0;
                             }
                             if ($crop_from_offset_x < 0) {
                                 $crop_from_offset_x = 0;
                             }
                             if ($crop_from_offset_y < 0) {
                                 $crop_from_offset_y = 0;
                             }
                         } else {
                             switch ($crop_from) {
                                 case 'north_west':
                                     $crop_from_offset_y = 0;
                                     $crop_from_offset_x = $w - $parameters["width"];
                                     break;
                                 case 'south_east':
                                     $crop_from_offset_x = 0;
                                     $crop_from_offset_y = $h - $parameters["height"];
                                     break;
                                 case 'south_west':
                                     $crop_from_offset_x = $w - $parameters["width"];
                                     $crop_from_offset_y = $h - $parameters["height"];
                                     break;
                                 case 'random':
                                     $crop_from_offset_x = rand(0, $w - $parameters["width"]);
                                     $crop_from_offset_y = rand(0, $h - $parameters["height"]);
                                     break;
                                 case 'north_east':
                                     $crop_from_offset_x = $crop_from_offset_y = 0;
                                     break;
                                 case 'center':
                                 default:
                                     if ($w > $parameters["width"]) {
                                         $crop_from_offset_x = ceil(($w - $parameters["width"]) / 2);
                                     } else {
                                         if ($h > $parameters["height"]) {
                                             $crop_from_offset_y = ceil(($h - $parameters["height"]) / 2);
                                         }
                                     }
                                     break;
                             }
                         }
                         if (!$this->handle->cropImage($parameters["width"], $parameters["height"], $crop_w_edge + $crop_from_offset_x, $crop_h_edge + $crop_from_offset_y)) {
                             $this->postError(1610, _t("Error during crop operation"), "WLPlugImagick->transform()");
                             return false;
                         }
                         $this->properties["width"] = $parameters["width"];
                         $this->properties["height"] = $parameters["height"];
                     } else {
                         if ($crop_w_edge || $crop_h_edge) {
                             if (!$this->handle->cropImage($w, $h, $crop_w_edge, $crop_h_edge)) {
                                 $this->postError(1610, _t("Error during crop operation"), "WLPlugImagick->transform()");
                                 return false;
                             }
                         }
                         $this->properties["width"] = $w;
                         $this->properties["height"] = $h;
                     }
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "ROTATE":
                 $angle = $parameters["angle"];
                 if ($angle > -360 && $angle < 360) {
                     if (!$this->handle->rotateImage("#FFFFFF", $angle)) {
                         $this->postError(1610, _t("Error during image rotate"), "WLPlugImagick->transform()");
                         return false;
                     }
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "DESPECKLE":
                 $radius = $parameters["radius"];
                 if (!$this->handle->despeckleImage()) {
                     $this->postError(1610, _t("Error during image despeckle"), "WLPlugImagick->transform:DESPECKLE()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "MEDIAN":
                 $radius = $parameters["radius"];
                 if ($radius < 0.1) {
                     $radius = 1;
                 }
                 if (!$this->handle->medianFilterImage($radius)) {
                     $this->postError(1610, _t("Error during image median filter"), "WLPlugImagick->transform:MEDIAN()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "SHARPEN":
                 $radius = $parameters["radius"];
                 if ($radius < 0.1) {
                     $radius = 1;
                 }
                 $sigma = $parameters["sigma"];
                 if ($sigma < 0.1) {
                     $sigma = 1;
                 }
                 if (!$this->handle->sharpenImage($radius, $sigma)) {
                     $this->postError(1610, _t("Error during image sharpen"), "WLPlugImagick->transform:SHARPEN()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "UNSHARPEN_MASK":
                 $radius = $parameters["radius"];
                 if ($radius < 0.1) {
                     $radius = 1;
                 }
                 $sigma = $parameters["sigma"];
                 if ($sigma < 0.1) {
                     $sigma = 1;
                 }
                 $threshold = $parameters["threshold"];
                 if ($threshold < 0.1) {
                     $threshold = 1;
                 }
                 $amount = $parameters["amount"];
                 if ($amount < 0.1) {
                     $amount = 1;
                 }
                 if (!$this->handle->unsharpMaskImage($radius, $sigma, $amount, $threshold)) {
                     $this->postError(1610, _t("Error during image unsharp mask"), "WLPlugImagick->transform:UNSHARPEN_MASK()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "SET":
                 while (list($k, $v) = each($parameters)) {
                     $this->set($k, $v);
                 }
                 break;
                 # -----------------------
         }
         return 1;
     } catch (Exception $e) {
         $this->postError(1610, _t("Imagick exception"), "WLPlugImagick->transform");
         return false;
     }
 }
Exemplo n.º 20
0
function material_photo_upload()
{
    global $_MooClass, $dbTablePre, $userid, $user, $pic_size_arr, $user_arr, $memcached;
    $and_uuid = isset($_GET['uuid']) ? $_GET['uuid'] : '';
    $uid = $_GET['uid'] = isset($_GET['uid']) ? $_GET['uid'] : '';
    if ($uid) {
        $userid = $mem_uid = $memcached->get('uid_' . $uid);
    }
    $checkuuid = check_uuid($and_uuid, $userid);
    if (!$checkuuid) {
        $error = "uuid_error";
        echo return_data($error, false);
        exit;
    }
    $user_arr = $user = MooMembersData($userid);
    $user_rank_id = get_userrank($userid);
    if (MOOPHP_ALLOW_FASTDB) {
        $usercer = MooFastdbGet('certification', 'uid', $userid);
    } else {
        $usercer = $_MooClass['MooMySQL']->getOne("SELECT * FROM {$dbTablePre}certification WHERE uid='{$userid}' LIMIT 1 ", true);
    }
    if ($_POST['isupload'] == '1') {
        //note 设定用户id
        $memberid = $userid;
        //note 设定用户上传图片大小限制 最小10240字节 = 10k 最大419430字节 = 400K
        $minfilesize = 20480;
        $maxfilesize = 1024000;
        $filesize = $_FILES['userfile']['size'];
        if ($filesize > $maxfilesize) {
            $notice = "请上传小于1000KB的照片。";
            echo return_data($notice);
            exit;
        }
        if ($filesize < $minfilesize) {
            $notice = "请上传大于20KB的照片。";
            echo return_data($notice);
            exit;
        }
        //note 判断文件类型
        $flag = '';
        $true_type = file_type($_FILES['userfile']['tmp_name']);
        $extname = strtolower(substr($_FILES['userfile']['name'], strrpos($_FILES['userfile']['name'], '.') + 1));
        $images = array('/jpg/', '/jpeg/', '/gif/', '/png/', '/JPG/', '/JPEG/', '/GIF/', '/PNG/');
        if (in_array('/' . $extname . '/', $images)) {
            foreach ($images as $v) {
                //note http://ask.wangmeng.cn/question/76
                if (preg_match($v, $_FILES['userfile']['type']) && ('image/' . $true_type == $_FILES['userfile']['type'] || 'image/p' . $true_type == $_FILES['userfile']['type'] || 'image/x-' . $true_type == $_FILES['userfile']['type'])) {
                    $file_content = file_get_contents($_FILES['userfile']['tmp_name']);
                    $low_file_content = strtolower($file_content);
                    $pos = strpos($low_file_content, '<?php');
                    if ($pos) {
                        $notice = "照片中含有不安全信息请重新上传";
                        echo return_data($notice);
                        exit;
                    } else {
                        $flag = 1;
                    }
                }
            }
        }
        //echo $true_type,'_',$flag,'_',$_FILES['userfile']['type'];exit;
        if ($flag != 1) {
            $notice = "请上传JPEG,JPG,PNG或GIF格式";
            echo return_data($notice);
            exit;
        }
        //note 设定该用户最多上传20张图片(形象照除外)
        $maxuploadnum = 20;
        //note 查询出来的总数
        $query = $_MooClass['MooMySQL']->getOne("select count(1) as num from `{$dbTablePre}pic` where `uid` = '{$memberid}' AND `isimage` = '0'", true);
        $total = $query['num'];
        //note 还可以上传多少张
        $leave_num = $maxuploadnum - $total;
        if ($leave_num <= 0) {
            $notice = '您已经有' . $maxuploadnum . '张照片了,';
            if ($user_arr['mainimg']) {
                $notice .= '不可以再上传了。';
            } else {
                $notice .= '请在相册中选一张作为形象照。';
            }
            echo return_data($notice);
            exit;
        }
        //note 设定相册名
        $album = '';
        //note 设定全局路径
        $orgin = "orgin";
        //note 原图文件夹名
        $thumb_path = PIC_PATH;
        //图片路径
        $timestat = time();
        $thumb_datedir = date("Y", $timestat) . "/" . date("m", $timestat) . "/" . date("d", $timestat);
        //原图路径
        $main_img_path = $thumb_path . "/" . $thumb_datedir . "/" . $orgin . "/";
        //note 调用文件操作类库,建立无限级目录
        $mkdirs = MooAutoLoad('MooFiles');
        !is_dir($main_img_path) && $mkdirs->fileMake($main_img_path, 0777);
        //note 上传到指定目录(原图),并且获得上传后的文件描述
        $upload = MooAutoLoad('MooUpload');
        $upload->config(array('targetDir' => $main_img_path, 'saveType' => '0'));
        $files = $upload->saveFiles('userfile');
        //note 获得图片路径和缩略图的路径
        $imgurl = $files[0]['path'] . $files[0]['name'] . "." . $files[0]['extension'];
        if ($files[0]['extension'] == 'gif') {
            $output = imagecreatefromgif($imgurl);
            imagegif($output, $imgurl, 100);
            imagedestroy($output);
        }
        $imgurl2 = $files[0]['path'] . $files[0]['name'] . "_nowater." . $files[0]['extension'];
        @copy($imgurl, $imgurl2);
        //拷贝一张无水印图片(用于形象照)
        $pic_name = $files[0]['name'] . "." . $files[0]['extension'];
        $pic_name2 = $files[0]['name'] . "_nowater." . $files[0]['extension'];
        $first = new Imagick($imgurl);
        //写入水印
        $second = new Imagick('public/system/images/logo_original.png');
        //$second->setImageOpacity (0.4);//设置透明度
        $dw = new ImagickDraw();
        $dw->setGravity(Imagick::GRAVITY_SOUTHEAST);
        //设置位置
        //$dw->setGravity(Imagick::GRAVITY_SOUTH);//设置位置
        $dw->composite($second->getImageCompose(), 0, 0, 50, 0, $second);
        $first->drawImage($dw);
        $first->writeImage($imgurl);
        //将第一张图片的大小控制成我们需要的大小
        list($width, $height) = getimagesize($imgurl);
        $d = $width / $height;
        $off_wh = off_WH($width, $height);
        $new_width = $off_wh['width'];
        $new_height = $off_wh['height'];
        unset($off_wh);
        $big_path = $files[0]['path'];
        $big_name = $files[0]['name'] . '.' . $files[0]['extension'];
        $image = MooAutoLoad('MooImage');
        $image->config(array('thumbDir' => $big_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $pic_name, 'waterMarkMinWidth' => '41', 'waterMarkMinHeight' => '57', 'waterMarkStatus' => 9));
        $image->thumb($new_width, $new_height, $imgurl);
        $image->waterMark();
        //note 缩略无水印图片
        $image->config(array('thumbDir' => $big_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $pic_name2, 'waterMarkMinWidth' => '41', 'waterMarkMinHeight' => '57', 'waterMarkStatus' => 9));
        $image->thumb($new_width, $new_height, $imgurl2);
        $image->waterMark();
        $thumb1_width = $pic_size_arr["1"]["width"];
        $thumb1_height = $pic_size_arr["1"]["height"];
        $thumb2_width = $pic_size_arr["2"]["width"];
        $thumb2_height = $pic_size_arr["2"]["height"];
        $thumb3_width = $pic_size_arr["3"]["width"];
        $thumb3_height = $pic_size_arr["3"]["height"];
        //note 生成日期目录
        $thumb1_path = $thumb_path . "/" . $thumb_datedir . "/" . $thumb1_width . "_" . $thumb1_height . "/";
        $thumb2_path = $thumb_path . "/" . $thumb_datedir . "/" . $thumb2_width . "_" . $thumb2_height . "/";
        $thumb3_path = $thumb_path . "/" . $thumb_datedir . "/" . $thumb3_width . "_" . $thumb3_height . "/";
        !is_dir($thumb1_path) && $mkdirs->fileMake($thumb1_path, 0777);
        !is_dir($thumb2_path) && $mkdirs->fileMake($thumb2_path, 0777);
        !is_dir($thumb3_path) && $mkdirs->fileMake($thumb3_path, 0777);
        //note 缩略图文件名
        $thumb_filename = md5($files[0]['name']) . "." . $files[0]['extension'];
        $c = 41 / 57;
        if ($d > $c) {
            $thumb1_width = 41;
            $b = $width / $thumb1_width;
            $thumb1_height = $height / $b;
        } else {
            $thumb1_height = 57;
            $b = $height / $thumb1_height;
            $thumb1_width = $width / $b;
        }
        $image->config(array('thumbDir' => $thumb1_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_filename, 'waterMarkMinWidth' => '41', 'waterMarkMinHeight' => '57', 'waterMarkStatus' => 9));
        $image->thumb($thumb1_width, $thumb1_height, $imgurl);
        $image->waterMark();
        $c = 139 / 189;
        if ($d > $c) {
            $thumb2_width = 139;
            $b = $width / $thumb2_width;
            $thumb2_height = $height / $b;
        } else {
            $thumb2_height = 189;
            $b = $height / $thumb2_height;
            $thumb2_width = $width / $b;
        }
        $image->config(array('thumbDir' => $thumb2_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_filename, 'waterMarkMinWidth' => '139', 'waterMarkMinHeight' => '189', 'waterMarkStatus' => 9));
        $image->thumb($thumb2_width, $thumb2_height, $imgurl);
        $image->waterMark();
        $c = 171 / 244;
        if ($d > $c) {
            $thumb3_width = 171;
            $b = $width / $thumb3_width;
            $thumb3_height = $height / $b;
        } else {
            $thumb3_height = 244;
            $b = $height / $thumb3_height;
            $thumb3_width = $width / $b;
        }
        $image->config(array('thumbDir' => $thumb3_path, 'thumbStatus' => '1', 'saveType' => '0', 'thumbName' => $thumb_filename, 'waterMarkMinWidth' => '171', 'waterMarkMinHeight' => '244', 'waterMarkStatus' => 9));
        $image->thumb($thumb3_width, $thumb3_height, $imgurl);
        $image->waterMark();
        //note 设定是否是形象照 1为形象照,0为普通照
        $isimage = (int) $_POST['isimage'];
        $updatetime = time();
        if ($isimage === 1) {
            $_MooClass['MooMySQL']->query("update `{$dbTablePre}members_base` set `mainimg`='{$imgurl}',`pic_date` = '{$thumb_datedir}',`pic_name` = '{$pic_name}' where `uid` = '{$memberid}'");
            $_MooClass['MooMySQL']->query("update `{$dbTablePre}members_search` set images_ischeck='2'  where `uid` = '{$memberid}'");
            if (MOOPHP_ALLOW_FASTDB) {
                $image_arr = array();
                $image_arr['mainimg'] = $imgurl;
                $image_arr['pic_date'] = $thumb_datedir;
                $image_arr['pic_name'] = $pic_name;
                $members_search['images_ischeck'] = '2';
                MooFastdbUpdate('members_base', 'uid', $memberid, $image_arr);
                MooFastdbUpdate('members_search', 'uid', $memberid, $members_search);
            }
            searchApi("members_man members_women")->updateAttr(array('images_ischeck'), array($memberid => array(0)));
            UpdateMembersSNS($userid, '修改了形象照');
        }
        //note 写入相册表
        $isimage = 0;
        //web_members.mainimg == web_pic.imgurl 即形象照
        $_MooClass['MooMySQL']->query("insert into `{$dbTablePre}pic` set `uid` = '{$memberid}',`isimage` = '{$isimage}',`album` = '{$album}',`imgurl` = '{$imgurl}',`pic_date` = '{$thumb_datedir}',`pic_name` = '{$pic_name}'");
        //提交会员动态makui
        UpdateMembersSNS($userid, '修改了相册');
        $notice = "成功";
        echo return_data($notice);
        exit;
    } else {
        $user1 = $user_arr;
    }
}
 public function text($text, $fontFile, $size = 12, $color = '#000000', $corner = self::CORNER_LEFT_TOP, $offsetX = 0, $offsetY = 0, $angle = 0)
 {
     $this->checkLoaded();
     /* This object will hold the font properties */
     $draw = new \ImagickDraw();
     /* Setting gravity to the center changes the origo
     			where annotation coordinates are relative to */
     $draw->setGravity(\Imagick::GRAVITY_CENTER);
     /* Use a custom truetype font */
     $draw->setFont($fontFile);
     /* Set the font size */
     $draw->setFontSize($size);
     $im = new \Imagick();
     /* Get the text properties */
     $properties = $im->queryFontMetrics($draw, $text);
     /* Region size for the watermark. Add some extra space on the sides  */
     $textWidth = intval($properties['textWidth'] + 5);
     $textHeight = intval($properties['textHeight'] + 5);
     /* Create a canvas using the font properties.
     			Add some extra space on width and height */
     $im->newImage($textWidth, $textHeight, new \ImagickPixel("transparent"));
     /* Use png format */
     $draw->setFillColor($color);
     $im->setImageFormat('png');
     $im->annotateImage($draw, 0, 0, 0, $text);
     list($posX, $posY) = $this->getCornerPosition($corner, $textWidth, $textHeight, $offsetX, $offsetY);
     /* Composite the watermark on the image to the top left corner */
     $this->_image->compositeImage($im, \Imagick::COMPOSITE_OVER, $posX, $posY);
     return $this;
 }
Exemplo n.º 22
0
 public function text($text, $color, $size, $font = 'FetteSteinschrift')
 {
     $font = BASE . "vendor/captcha/fonts/en/" . $font . ".ttf";
     $draw = new \ImagickDraw();
     $draw->setGravity(\Imagick::GRAVITY_CENTER);
     $draw->setFont($font);
     $draw->setFontSize($size);
     $draw->setFillColor(new \ImagickPixel($color));
     $im = new \imagick();
     $properties = $im->queryFontMetrics($draw, $text);
     $im->newImage(intval($properties['textWidth'] + 5), intval($properties['textHeight'] + 5), new \ImagickPixel('transparent'));
     $im->setImageFormat('png');
     $im->annotateImage($draw, 0, 0, 0, $text);
     return $im;
 }
Exemplo n.º 23
0
 public function addWatermarkTextMosaic($text = "Copyright", $font = "Courier", $size = 20, $color = "grey70", $maskColor = "grey30", $position = \Imagick::GRAVITY_SOUTHEAST)
 {
     $watermark = new \Imagick();
     $draw = new \ImagickDraw();
     $watermark->newImage(140, 80, new \ImagickPixel('none'));
     $draw->setFont($font);
     $draw->setFillColor('grey');
     $draw->setFillOpacity(0.4);
     $draw->setGravity(\Imagick::GRAVITY_NORTHWEST);
     $watermark->annotateImage($draw, 10, 10, 0, $text);
     $draw->setGravity(\Imagick::GRAVITY_SOUTHEAST);
     $watermark->annotateImage($draw, 5, 15, 0, $text);
     for ($w = 0; $w < $this->getImage()->getImageWidth(); $w += 140) {
         for ($h = 0; $h < $this->getImage()->getImageHeight(); $h += 80) {
             $this->getImage()->compositeImage($watermark, \Imagick::COMPOSITE_OVER, $w, $h);
         }
     }
 }
Exemplo n.º 24
0
    static function nonImageAddTexte($text, $fontfile, $fontsize)
    {
        $svg = '<?xml version="1.0" encoding="utf-8"?>

<!-- The icon can be used freely in both personal and commercial projects with no attribution required, but always appreciated.
You may NOT sub-license, resell, rent, redistribute or otherwise transfer the icon without express written permission from iconmonstr.com -->

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 width="512px" height="512px" viewBox="0 0 512 512" xml:space="preserve">
<defs>
<linearGradient id="degrade" x1="100%" y1="0" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#898989; stop-opacity:0.2;"/>
<stop offset="40%" style="stop-color:#464646; stop-opacity:1;"/>
<stop offset="100%" style="stop-color:#111111; stop-opacity:0.7;"/>
</linearGradient>
<linearGradient id="degrade1" x1="100%" y1="0" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#111111; stop-opacity:0.7;"/>
<stop offset="40%" style="stop-color:#AAAAAA; stop-opacity:1;"/>
<stop offset="100%" style="stop-color:#F0F0F0; stop-opacity:0.2;"/>
</linearGradient>

<style type="text/css">
#stop1{ stop-color:chartreuse; stop-opacity:0.2; } #stop2{ stop-color:cornflowerblue; stop-opacity:1; } #stop3{ stop-color:chartreuse; stop-opacity:0.7; }

</style>
</defs>
<path style="fill:url(#degrade); stroke:#BBBBBB; stroke-width:2px;" id="video-icon" d="M50,60.345v391.311h412V60.345H50z M137.408,410.862H92.354v-38.747h45.055V410.862z M137.408,343.278
	H92.354v-38.747h45.055V343.278z M137.408,275.372H92.354v-38.747h45.055V275.372z M137.408,208.111H92.354v-38.748h45.055V208.111z
	 M137.408,140.526H92.354v-38.747h45.055V140.526z M337.646,410.862H177.961V275.694h159.685V410.862z M337.646,236.947H177.961
	V101.779h159.685V236.947z M423.253,410.862h-45.054v-38.747h45.054V410.862z M423.253,343.278h-45.054v-38.747h45.054V343.278z
	 M423.253,275.372h-45.054v-38.747h45.054V275.372z M423.253,208.111h-45.054v-38.748h45.054V208.111z M423.253,140.526h-45.054
	v-38.747h45.054V140.526z"/>
</svg>
';
        $im2 = new \Imagick();
        $im2->setBackgroundColor(new \ImagickPixel('transparent'));
        $im2->readimageblob($svg);
        $im2->setImageFormat("png");
        $im2->adaptiveResizeImage(140, 140);
        /*Optional, if you need to resize*/
        //return $im2->getimageblob();
        $im = new \Imagick();
        $im->newimage(260, 300, new \ImagickPixel('#999999'), "jpeg");
        $im->compositeimage($im2, \Imagick::COMPOSITE_DEFAULT, 60, 80);
        $widthmax = $im->getImageGeometry()["width"];
        $draw = new \ImagickDraw();
        /* On commence un nouveau masque nommé "gradient" */
        $draw->setFillColor('#FFFFFF');
        /* Font properties */
        $draw->setFont($fontfile);
        $draw->setFontSize($fontsize);
        $draw->setGravity(\Imagick::GRAVITY_NORTH);
        $words = explode(' ', $text);
        //Test si la fontsize n'est pas trop grosse pour un mot
        $i = 0;
        while ($i < count($words)) {
            $lineSize = $im->queryfontmetrics($draw, $words[$i])["textWidth"];
            if ($lineSize < $widthmax) {
                $i++;
            } else {
                $fontsize--;
                $draw->setFontSize($fontsize);
            }
        }
        $res = $words[0];
        for ($i = 1; $i < count($words); $i++) {
            $lineSize = $im->queryfontmetrics($draw, $res . " " . $words[$i]);
            if ($lineSize["textWidth"] < $widthmax) {
                $res .= " " . $words[$i];
            } else {
                $res .= "\n" . $words[$i];
            }
        }
        /* Create text */
        $im->annotateImage($draw, 0, 0, 0, $res);
        return $im->getimageblob();
    }
Exemplo n.º 25
0
 function waterMarkFont()
 {
     if ($this->param['water_mark_color']) {
         $color = $this->param['water_mark_color'];
     } else {
         $color = '#000000';
     }
     $r = hexdec(substr($color, 1, 2));
     $g = hexdec(substr($color, 3, 2));
     $b = hexdec(substr($color, 5, 2));
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel($color));
     //设置填充颜色
     $draw->setFont($this->param['water_mark_font']);
     //设置文本字体,要求ttf或者ttc字体,可以绝对或者相对路径
     $draw->setFontSize($this->param['water_mark_fontsize']);
     //设置字号
     switch ($this->param['water_mark_pos']) {
         case 0:
         case 1:
             $gravity = Imagick::GRAVITY_NORTHWEST;
             //'NorthWest';
             break;
         case 2:
             $gravity = Imagick::GRAVITY_NORTH;
             //'North';
             break;
         case 3:
             $gravity = Imagick::GRAVITY_NORTHEAST;
             //'NorthEast';
             break;
         case 4:
             $gravity = Imagick::GRAVITY_WEST;
             //'West';
             break;
         case 5:
             $gravity = Imagick::GRAVITY_CENTER;
             //'Center';
             break;
         case 6:
             $gravity = Imagick::GRAVITY_EAST;
             //'East';
             break;
         case 7:
             $gravity = Imagick::GRAVITY_SOUTHWEST;
             //'SouthWest';
             break;
         case 8:
             $gravity = Imagick::GRAVITY_SOUTH;
             //'South';
             break;
         case 9:
             $gravity = Imagick::GRAVITY_SOUTHEAST;
             break;
     }
     $draw->setGravity($gravity);
     if ($this->image_type == 'GIF') {
         $color_transparent = new ImagickPixel("transparent");
         $dest = new Imagick();
         foreach ($this->image as $frame) {
             $page = $frame->getImagePage();
             $tmp = new Imagick();
             $tmp->newImage($page['width'], $page['height'], $color_transparent, 'gif');
             $tmp->compositeImage($frame, Imagick::COMPOSITE_OVER, $page['x'], $page['y']);
             $tmp->annotateImage($draw, 0, 0, $this->param['water_mark_angle'], $this->param['water_mark_string']);
             $dest->addImage($tmp);
             $dest->setImagePage($tmp->getImageWidth(), $tmp->getImageHeight(), 0, 0);
             $dest->setImageDelay($frame->getImageDelay());
             $dest->setImageDispose($frame->getImageDispose());
         }
         $dest->coalesceImages();
         $this->image->destroy();
         $this->image = $dest;
     } else {
         if ($this->param['water_mark_opacity']) {
             $draw->setFillOpacity($this->param['water_mark_opacity'] / 100);
         }
         $this->image->annotateImage($draw, 0, 0, $this->param['water_mark_angle'], $this->param['water_mark_string']);
     }
 }
Exemplo n.º 26
0
 protected function drawPublisherDate($right, $bottom)
 {
     $text = $this->publisher . ', ' . $this->datePublished;
     if (empty($text)) {
         return 0;
     }
     $draw = new \ImagickDraw();
     $draw->setFillColor($this->textColor);
     $draw->setGravity(\Imagick::GRAVITY_SOUTHEAST);
     $draw->setFontSize(16);
     $metrics = $this->image->queryFontMetrics($draw, $text);
     $textheight = $metrics['textHeight'] - $metrics['descender'];
     //$image->annotateImage($draw, $right, $bottom, 0,$this->publisher.", ".$year." ".$color);
     $this->image->annotateImage($draw, $right, $bottom, 0, $text);
     return $textheight;
 }
Exemplo n.º 27
0
 /**
  * Creates image with text
  * @param int $sizeX
  * @param int $sizeY
  * @param string $text
  * @param string $generator
  * @return \Imagick
  */
 public function mkCapcha($sizeX, $sizeY, $text, $generator = self::METHOD_DEFAULT)
 {
     // init image
     $image = new \Imagick();
     $image->newImage($sizeX, $sizeY, new \ImagickPixel('white'));
     $image->setImageFormat('png');
     switch ($generator) {
         case self::METHOD_GRAYNOISE:
             $draw = new \ImagickDraw();
             $draw->setFontSize(35);
             $draw->setFontWeight(900);
             $draw->setGravity(\imagick::GRAVITY_CENTER);
             $image->addNoiseImage(\imagick::NOISE_LAPLACIAN);
             $image->annotateImage($draw, 0, 0, 0, $text);
             $image->charcoalImage(2, 1.5);
             $image->addNoiseImage(\imagick::NOISE_LAPLACIAN);
             $image->gaussianBlurImage(1, 1);
             break;
         case self::METHOD_GRAYBLUR:
             $draw = new \ImagickDraw();
             $order = [];
             for ($i = 0; $i < strlen($text); $i++) {
                 $order[$i] = $i;
             }
             shuffle($order);
             for ($j = 0; $j < 2; $j++) {
                 shuffle($order);
                 $image->gaussianBlurImage(15, 3);
                 for ($n = 0; $n < strlen($text); $n++) {
                     $i = $order[$n];
                     $draw->setFont(__DIR__ . '/Capcha/DejaVuSans.ttf');
                     $draw->setFontSize($j ? rand($sizeY * 3 / 5, $sizeY * 5 / 6) : rand($sizeY * 4 / 6, $sizeY * 5 / 6));
                     $draw->setFontWeight(rand(100, 900));
                     $draw->setGravity(\imagick::GRAVITY_CENTER);
                     $image->annotateImage($draw, ($i - strlen($text) / 2) * $sizeX / (strlen($text) + 2.3), 0, rand(-25, 25), $text[$i]);
                     $image->gaussianBlurImage(1, 1);
                 }
             }
             break;
     }
     return $image;
 }
Exemplo n.º 28
0
 public function watermarkText($overlayText, $position, $param = array('rotation' => 0, 'opacity' => 50, 'color' => 'FFF', 'size' => null))
 {
     $imagick = new Imagick();
     $imagick->readImage($this->_file);
     $size = null;
     if ($param['size']) {
         $size = $param['size'];
     } else {
         $text = new ImagickDraw();
         $text->setFontSize(12);
         $text->setFont($this->_watermarkFont);
         $im = new Imagick();
         $stringBox12 = $im->queryFontMetrics($text, $overlayText, false);
         $string12 = $stringBox12['textWidth'];
         $size = (int) ($this->_width / 2) * 12 / $string12;
         $im->clear();
         $im->destroy();
         $text->clear();
         $text->destroy();
     }
     $draw = new ImagickDraw();
     $draw->setFont($this->_watermarkFont);
     $draw->setFontSize($size);
     $draw->setFillOpacity($param['opacity']);
     switch ($position) {
         case Gio_Image_Abstract::POS_TOP_LEFT:
             $draw->setGravity(Imagick::GRAVITY_NORTHWEST);
             break;
         case Gio_Image_Abstract::POS_TOP_RIGHT:
             $draw->setGravity(Imagick::GRAVITY_NORTHEAST);
             break;
         case Gio_Image_Abstract::POS_MIDDLE_CENTER:
             $draw->setGravity(Imagick::GRAVITY_CENTER);
             break;
         case Gio_Image_Abstract::POS_BOTTOM_LEFT:
             $draw->setGravity(Imagick::GRAVITY_SOUTHWEST);
             break;
         case Gio_Image_Abstract::POS_BOTTOM_RIGHT:
             $draw->setGravity(Imagick::GRAVITY_SOUTHEAST);
             break;
         default:
             throw new Exception('Do not support ' . $position . ' type of alignment');
             break;
     }
     $draw->setFillColor('#' . $param['color']);
     $imagick->annotateImage($draw, 5, 5, $param['rotation'], $overlayText);
     $imagick->writeImage($this->_file);
     $imagick->clear();
     $imagick->destroy();
     $draw->clear();
     $draw->destroy();
 }
Exemplo n.º 29
0
 /**
  * Execute a text
  *
  * @param string $text
  * @param int    $offsetX
  * @param int    $offsetY
  * @param float  $opacity
  * @param int    $color
  * @param int    $size
  * @param string $font_file
  *
  * @return static
  */
 public function text($text, $offsetX = 0, $offsetY = 0, $opacity = 1.0, $color = 0x0, $size = 12, $font_file = null)
 {
     $draw = new \ImagickDraw();
     $textColor = sprintf('rgb(%u,%u,%u)', $color >> 16 & 0xff, $color >> 8 & 0xff, $color & 0xff);
     $draw->setFillColor(new \ImagickPixel($textColor));
     if ($font_file) {
         $draw->setFont($this->alias->resolve($font_file));
     }
     $draw->setFontSize($size);
     $draw->setFillOpacity($opacity);
     $draw->setGravity(\Imagick::GRAVITY_NORTHWEST);
     $this->_image->annotateImage($draw, $offsetX, $offsetY, 0, $text);
     $draw->destroy();
     return $this;
 }
Exemplo n.º 30
0
 function create_thumbnail($filename, $save2disk = true, $resize_type = 0)
 {
     $filename = $this->basename($filename);
     if ($this->is_image($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $filename) == true) {
         $extension = $this->file_extension($filename);
         $thumbnail = $this->thumbnail_name($filename);
         if ($save2disk == true) {
             // Seemed easier to build the image resize upload
             // option into the already established thumbnail function
             // instead of waisting time trying to chop it up for new one.
             if ($resize_type > 0 && $resize_type <= 8) {
                 $thumbnail = $filename;
                 $this->mmhclass->info->config['advanced_thumbnails'] = false;
                 $size_values = array(1 => array("w" => 100, "h" => 75), 2 => array("w" => 150, "h" => 112), 3 => array("w" => 320, "h" => 240), 4 => array("w" => 640, "h" => 480), 5 => array("w" => 800, "h" => 600), 6 => array("w" => 1024, "h" => 768), 7 => array("w" => 1280, "h" => 1024), 8 => array("w" => 1600, "h" => 1200));
                 $thumbnail_size = $size_values[$resize_type];
             } else {
                 $thumbnail_size = $this->scale($filename, $this->mmhclass->info->config['thumbnail_width'], $this->mmhclass->info->config['thumbnail_height']);
             }
             if ($this->manipulator == "imagick") {
                 // New Design of Advanced Thumbnails created by: IcyTexx - http://www.hostili.com
                 // Classic Design of Advanced Thumbnails created by: Mihalism Technologies - http://www.mihalism.net
                 $canvas = new Imagick();
                 $athumbnail = new Imagick();
                 $imagick_version = $canvas->getVersion();
                 // Imagick needs to start giving real version number, not build number.
                 $new_thumbnails = version_compare($imagick_version['versionNumber'], "1621", ">=") == true ? true : false;
                 $athumbnail->readImage("{$this->mmhclass->info->root_path}{$this->mmhclass->info->config['upload_path']}{$filename}[0]");
                 $athumbnail->flattenImages();
                 $athumbnail->orgImageHeight = $athumbnail->getImageHeight();
                 $athumbnail->orgImageWidth = $athumbnail->getImageWidth();
                 $athumbnail->orgImageSize = $athumbnail->getImageLength();
                 $athumbnail->thumbnailImage($thumbnail_size['w'], $thumbnail_size['h']);
                 if ($this->mmhclass->info->config['advanced_thumbnails'] == true) {
                     $thumbnail_filesize = $this->format_filesize($athumbnail->orgImageSize, true);
                     $resobar_filesize = $thumbnail_filesize['f'] < 0 || $thumbnail_filesize['c'] > 9 ? $this->mmhclass->lang['5454'] : sprintf("%s%s", round($thumbnail_filesize['f']), $this->mmhclass->lang['7071'][$thumbnail_filesize['c']]);
                     if ($new_thumbnails == true) {
                         $textdraw = new ImagickDraw();
                         $textdrawborder = new ImagickDraw();
                         if ($athumbnail->getImageWidth() > 113) {
                             $textdraw->setFillColor(new ImagickPixel("white"));
                             $textdraw->setFontSize(9);
                             $textdraw->setFont("{$mmhclass->info->root_path}css/fonts/sf_fedora_titles.ttf");
                             $textdraw->setFontWeight(900);
                             $textdraw->setGravity(8);
                             $textdraw->setTextKerning(1);
                             $textdraw->setTextAntialias(false);
                             $textdrawborder->setFillColor(new ImagickPixel("black"));
                             $textdrawborder->setFontSize(9);
                             $textdrawborder->setFont("{$mmhclass->info->root_path}css/fonts/sf_fedora_titles.ttf");
                             $textdrawborder->setFontWeight(900);
                             $textdrawborder->setGravity(8);
                             $textdrawborder->setTextKerning(1);
                             $textdrawborder->setTextAntialias(false);
                             $array_x = array("-1", "0", "1", "1", "1", "0", "-1", "-1");
                             $array_y = array("-1", "-1", "-1", "0", "1", "1", "1", "0");
                             foreach ($array_x as $key => $value) {
                                 $athumbnail->annotateImage($textdrawborder, $value, 3 - $array_y[$key], 0, "{$athumbnail->orgImageWidth}x{$athumbnail->orgImageHeight} - {$resobar_filesize}");
                             }
                             $athumbnail->annotateImage($textdraw, 0, 3, 0, "{}x{$athumbnail->orgImageHeight} - {$resobar_filesize}");
                         }
                     } else {
                         $transback = new Imagick();
                         $canvasdraw = new ImagickDraw();
                         $canvas->newImage($athumbnail->getImageWidth(), $athumbnail->getImageHeight() + 12, new ImagickPixel("black"));
                         $transback->newImage($canvas->getImageWidth(), $canvas->getImageHeight() - 12, new ImagickPixel("white"));
                         $canvas->compositeImage($transback, 40, 0, 0);
                         $canvasdraw->setFillColor(new ImagickPixel("white"));
                         $canvasdraw->setGravity(8);
                         $canvasdraw->setFontSize(10);
                         $canvasdraw->setFontWeight(900);
                         $canvasdraw->setFont("AvantGarde-Demi");
                         $canvas->annotateImage($canvasdraw, 0, 0, 0, "{$athumbnail->orgImageWidth}x{$athumbnail->orgImageHeight} - {$resobar_filesize}");
                         $canvas->compositeImage($athumbnail, 40, 0, 0);
                         $athumbnail = $canvas->clone();
                     }
                 }
                 if ($this->mmhclass->info->config['thumbnail_type'] == "jpeg") {
                     $athumbnail->setImageFormat("jpeg");
                     $athumbnail->setImageCompression(9);
                 } else {
                     $athumbnail->setImageFormat("png");
                 }
                 $athumbnail->writeImage($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $thumbnail);
             } else {
                 // I hate GD. Piece of crap supports nothing. NOTHING!
                 if (in_array($extension, array("png", "gif", "jpg", "jpeg")) == true) {
                     $function_extension = str_replace("jpg", "jpeg", $extension);
                     $image_function = "imagecreatefrom{$function_extension}";
                     $image = $image_function($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $filename);
                     $imageinfo = $this->get_image_info($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $this->basename($filename));
                     $thumbnail_image = imagecreatetruecolor($thumbnail_size['w'], $thumbnail_size['h']);
                     $index = imagecolortransparent($thumbnail_image);
                     if ($index < 0) {
                         $white = imagecolorallocate($thumbnail_image, 255, 255, 255);
                         imagefill($thumbnail_image, 0, 0, $white);
                     }
                     imagecopyresampled($thumbnail_image, $image, 0, 0, 0, 0, $thumbnail_size['w'], $thumbnail_size['h'], $imageinfo['width'], $imageinfo['height']);
                     $image_savefunction = sprintf("image%s", $this->mmhclass->info->config['thumbnail_type'] == "jpeg" ? "jpeg" : "png");
                     $image_savefunction($thumbnail_image, $this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $thumbnail);
                     chmod($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $thumbnail, 0644);
                     imagedestroy($image);
                     imagedestroy($thumbnail_image);
                 } else {
                     trigger_error("Image format not supported by GD", E_USER_ERROR);
                 }
             }
             chmod($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $thumbnail, 0644);
         } else {
             readfile($this->mmhclass->info->root_path . $this->mmhclass->info->config['upload_path'] . $thumbnail);
         }
     }
 }