public function process($args)
 {
     if (isset($args[0])) {
         $rotation = $args[0];
     } else {
         $rotation = mt_rand(-5, 5);
     }
     if (isset($args[1])) {
         $signature = $args[1];
     }
     /* -------------------------- */
     $frame_path = DOCROOT . "/staticfiles/img/polaroids/blog_polaroid_frame.png";
     if (!isset($frame_path) or !file_exists($frame_path)) {
         return;
     }
     // Load the frame and crop the requested image
     $frame = new Gmagick();
     $frame->readImage($frame_path);
     $w = $frame->getimagewidth();
     $h = $frame->getimageheight();
     $this->crop(85, 90);
     $x = 10;
     $y = 15;
     $this->image->borderImage("transparent", $x, $y);
     // Have to add a border as the x displacement in compositeImage() is broken!
     $this->image->compositeImage($frame, Gmagick::COMPOSITE_OVER, 0, 0);
     // Some comp styles seem to throw errors!
     // Add the signature if we have been asked for one
     if (isset($signature)) {
         $sig_path = DOCROOT . "/staticfiles/img/polaroids/" . $signature . "_sig.png";
         if (!file_exists($sig_path)) {
             return;
         }
         $sig = new Gmagick();
         $sig->readImage($sig_path);
         $sw = $sig->getimagewidth();
         $sh = $sig->getimageheight();
         $x = ($this->image->getimagewidth() - $sig->getimagewidth()) / 2;
         $y = 330;
         // Have to add a border as the x displacement in compositeImage() is broken!
         $sig->borderImage("transparent", $x, $y);
         $this->image->compositeImage($sig, Gmagick::COMPOSITE_OVER, 0, 0);
         // Some comp styles seem to throw errors!
     }
     // Rotate the image
     if ($rotation != 0) {
         $frame->magnifyimage();
         $frame->magnifyimage();
         $this->image->rotateimage('transparent', $rotation);
         $frame->minifyimage();
         $frame->minifyimage();
     }
 }
Пример #2
0
 public function process($args)
 {
     $frame_path = Kohana::config('recipe.compositeframe');
     if (!isset($frame_path) or !file_exists($frame_path)) {
         return;
     }
     $frame = new Gmagick();
     $frame->readImage($frame_path);
     $w = $frame->getimagewidth();
     $h = $frame->getimageheight();
     $this->crop($w, $h);
     $this->image->compositeImage($frame, Gmagick::COMPOSITE_OVER, 0, 0);
     // Some comp styles seem to throw errors!
 }
 private function drawRectangleAndReplaceExistImg($image, $height, $width)
 {
     // прямоугольник рисуем снизу изображения высотой 8% от высоты изображения
     $heightRectagle = $height * 0.08;
     $gmagicDraw = new GmagickDraw();
     $gmagicDraw->setfillcolor("#fff");
     $gmagicDraw->rectangle(0, $height - $heightRectagle, $width, $height);
     $gImage = new Gmagick();
     $gImage->readImage($image);
     $gImage->drawimage($gmagicDraw);
     $gImage->writeimage($image);
     $gImage->destroy();
 }
Пример #4
0
 function thumbnail($upfiledir, $src, $tName, $tw = '', $th = '', $scale = true, $tDir = "thumb")
 {
     global $iCMS;
     $R = array();
     $tw = empty($tw) ? $iCMS->config['thumbwidth'] : (int) $tw;
     $th = empty($th) ? $iCMS->config['thumbhight'] : (int) $th;
     if ($tw && $th) {
         list($width, $height, $type) = @getimagesize($src);
         if ($width < 1 && $height < 1) {
             $R['width'] = $tw;
             $R['height'] = $th;
             $R['src'] = $src;
             return $R;
         }
         if ($width > $tw || $height > $th) {
             $R['src'] = $upfiledir . $tDir . "/" . $tName . '_' . $tw . 'x' . $th . '.' . substr(strrchr($src, "."), 1);
             if (in_array('Gmagick', get_declared_classes())) {
                 $image = new Gmagick();
                 $image->readImage($src);
                 $im = self::scale(array("tw" => $tw, "th" => $th, "w" => $image->getImageWidth(), "h" => $image->getImageHeight()));
                 $image->resizeImage($im['w'], $im['h'], null, 1);
                 $image->cropImage($tw, $th, 0, 0);
                 //$image->thumbnailImage($gm_w,$gm_h);
                 FS::mkdir($upfiledir . $tDir);
                 $image->writeImage($R['src']);
                 $image->destroy();
             } else {
                 $im = self::scale(array("tw" => $tw, "th" => $th, "w" => $width, "h" => $height), $scale);
                 $R['width'] = $im['w'];
                 $R['height'] = $im['h'];
                 $res = self::imagecreate($type, $src);
                 if ($res) {
                     $thumb = imagecreatetruecolor($im['w'], $im['h']);
                     imagecopyresampled($thumb, $res, 0, 0, 0, 0, $im['w'], $im['h'], $width, $height);
                     //PHP_VERSION != '4.3.2' && self::UnsharpMask($thumb);
                     FS::mkdir($upfiledir . $tDir);
                     self::image($thumb, $type, $R['src']);
                 } else {
                     $R['src'] = $src;
                 }
             }
         } else {
             $R['width'] = $width;
             $R['height'] = $height;
             $R['src'] = $src;
         }
         return $R;
     }
 }
Пример #5
0
 $file_name = str_replace(' ', '_', $file_name);
 //if (in_array($type,$allowedExtensions)) {
 // Edit upload location here
 $destination_path = 'files/chat_files/';
 $target_path = UPLOAD_PATH . $name;
 $Thumb_Path = UPLOAD_PATH . 'thumbs/' . $name;
 if (move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
     $result = 1;
     //$sql = execute_sqlQuery("UPDATE tbl_CompInfo SET comp_Logo='$name' WHERE comp_Id='$comp_Id'");
     $MF->updateDiskSpace($size);
     if (in_array($file_type, array("image/gif", "image/jpeg", "image/png", "image/pjpeg", "image/bmp"))) {
         try {
             copy($target_path, $Thumb_Path);
             // initialize object
             $image = new Gmagick();
             $image->readImage($target_path);
             $old_width = $image->getImageWidth();
             $old_height = $image->getImageHeight();
             $new_width = 200;
             $new_height = $old_height / $old_width * $new_width;
             exec("gm mogrify -resize {$new_width}x{$new_height} -quality 90 " . APP_INSTALLPATH . UPLOAD_PATH . "thumbs/{$name}");
             //$image->thumbnailImage($new_width, $new_height);
             //$thumbFile = dirname($file) . '/' . basename($target_path, '.JPG') . '.thumb.jpg';
             //$image->writeImage($Thumb_Path);
             /*$thumb_size = $image->getsize();
             		$MF->updateDiskSpace($thumb_size);*/
             // free resource handle
             $image->destroy();
         } catch (Exception $e) {
             die($e->getMessage());
         }
Пример #6
0
 /**
  * Apply transformations on image
  *
  * @param string $source Source image
  * @param array  $params Transformations and parameters
  * @param string $store  Temporary store on disk
  *
  * @return string
  */
 public function transform($source, $params, $store = null)
 {
     try {
         $image = new \Gmagick();
         $image->readImage($source);
         if (isset($params['negate'])) {
             $this->canNegate();
         }
         if (isset($params['rotate'])) {
             $image->rotateImage('#000', $params['rotate']['angle']);
         }
         if (isset($params['crop'])) {
             $image->cropImage($params['crop']['width'], $params['crop']['height'], $params['crop']['x'], $params['crop']['y']);
         }
         if (isset($params['contrast'])) {
             $this->canContrast();
         }
         if (isset($params['brightness'])) {
             $value = (int) $params['brightness'];
             $brightness = null;
             if ($value <= 0) {
                 $brightness = $value + 100;
             } else {
                 $brightness = $value * 3 + 100;
             }
             $image->modulateImage($brightness, 100, 100);
         }
         $ret = null;
         if ($store !== null) {
             $ret = $image->writeImage($store);
         } else {
             $ret = $image->getImageBlob();
         }
         $image->destroy();
         return $ret;
     } catch (\GmagickException $e) {
         $image->destroy();
         throw new \RuntimeException($e->getMessage());
     }
 }
<?php

require_once "TestSettings.php";
dl("gmagick.so");
$input_file = __DIR__ . '/' . TestSettings::INPUT_FILE;
$output_file = __DIR__ . "/output/gmagick.jpg";
$timers = ['new' => 0, 'open' => 0, 'get_info' => 0, 'scale' => 0, 'rotate' => 0, 'paste' => 0, 'save' => 0];
for ($i = 0; $i < TestSettings::NUM_RUNS; $i++) {
    $time_open_start = microtime(true);
    $Image1 = new Gmagick();
    $Image1->readImage($input_file);
    $timers['open'] += microtime(true) - $time_open_start;
    $time_get_info_start = microtime(true);
    $width = $Image1->getImageWidth();
    $height = $Image1->getImageHeight();
    $timers['get_info'] += microtime(true) - $time_get_info_start;
    $time_get_info_start = microtime(true);
    $new_width = ceil($width / TestSettings::DOWNSCALE_FACTOR);
    $new_height = ceil($height / TestSettings::DOWNSCALE_FACTOR);
    $timers['get_info'] += microtime(true) - $time_get_info_start;
    $time_scale_start = microtime(true);
    $Image1->scaleImage($new_width, $new_height);
    $timers['scale'] += microtime(true) - $time_scale_start;
    $time_rotate_start = microtime(true);
    $WhiteColor = new GmagickPixel('white');
    $Image1->rotateImage($WhiteColor, TestSettings::ROTATE_ANGLE);
    $timers['rotate'] += microtime(true) - $time_rotate_start;
    $time_new_start = microtime(true);
    $Image2 = new Gmagick();
    $Image2->newImage(TestSettings::OUTPUT_IMAGE_WIDTH, TestSettings::OUTPUT_IMAGE_HEIGHT, 'white');
    $timers['new'] += microtime(true) - $time_new_start;
Пример #8
0
 public function process($args)
 {
     if (isset($args[0]) and is_numeric($args[0])) {
         $rotation = $args[0];
     } else {
         $rotation = mt_rand(-5, 5);
     }
     if (isset($args[1])) {
         $signature = $args[1];
     }
     if (isset($args[2])) {
         $role = $args[2];
     }
     /* -------------------------- */
     $frame_path = DOCROOT . "/staticfiles/img/polaroids/polaroid_frame.png";
     if (!isset($frame_path) or !file_exists($frame_path)) {
         return;
     }
     // Load the frame and crop the requested image
     $frame = new Gmagick();
     $frame->readImage($frame_path);
     $w = $frame->getimagewidth();
     $h = $frame->getimageheight();
     $this->crop(285, 294);
     $x = 28;
     $y = 31;
     $this->image->borderImage("transparent", $x, $y);
     // Have to add a border as the x displacement in compositeImage() is broken!
     $frame->compositeImage($this->image, Gmagick::COMPOSITE_OVER, 0, 0);
     // Some comp styles seem to throw errors!
     $this->image = $frame;
     // Add the signature if we have been asked for one
     if (isset($signature)) {
         $sig_path = DOCROOT . "/staticfiles/img/polaroids/" . $signature . "_sig.png";
         if (file_exists($sig_path)) {
             $sig = new Gmagick();
             $sig->readImage($sig_path);
             $sw = $sig->getimagewidth();
             $sh = $sig->getimageheight();
             $x = ($this->image->getimagewidth() - $sig->getimagewidth()) / 2;
             $y = 330;
             // Have to add a border as the x displacement in compositeImage() is broken!
             $sig->borderImage("transparent", $x, $y);
             $this->image->compositeImage($sig, Gmagick::COMPOSITE_OVER, 0, 0);
             // Some comp styles seem to throw errors!
         }
     }
     // Add the role if we've been asked for one
     if (isset($role)) {
         $font_size = 17;
         $draw = new GmagickDraw();
         $draw->setFontSize($font_size);
         $draw->setFont(DOCROOT . "/staticfiles/img/polaroids/monaco.ttf");
         $draw->setFillColor('#666');
         $text_width = $font_size * strlen($role) * 0.77;
         // Seems to be about a 0.77 ration for monaco between width and height
         $x = ($this->image->getimagewidth() - $text_width) / 2;
         $this->image->annotateimage($draw, $x, 395, 0, $role);
     }
     // Rotate the image
     if ($rotation != 0) {
         $frame->magnifyimage();
         $frame->magnifyimage();
         $this->image->rotateimage('transparent', $rotation);
         $frame->minifyimage();
         $frame->minifyimage();
     }
 }
Пример #9
0
                    $res = imagecreatefromgif($src);
                    break;
                case 2:
                    $res = imagecreatefromjpeg($src);
                    break;
                case 3:
                    $res = imagecreatefrompng($src);
                    break;
            }
            return $res;
        }
    }
}
if (fsexists($src)) {
    $image = new Gmagick();
    $image->readImage($src);
    $scale = array("tw" => $tw, "th" => $th, "w" => $image->getImageWidth(), "h" => $image->getImageHeight());
    if ($tw > 0 && $th > 0) {
        $im = scale($scale);
        $image->resizeImage($im['w'], $im['h'], null, 1);
        $x = $y = 0;
        $im['w'] > $im['tw'] && ($x = ceil(($im['w'] - $im['tw']) / 3));
        $im['h'] > $im['th'] && ($y = ceil(($im['h'] - $im['th']) / 3));
        $image->cropImage($tw, $th, $x, $y);
    } else {
        empty($scale['th']) && ($scale['th'] = 9999999);
        $im = bitscale($scale);
        $image->resizeImage($im['w'], $im['h'], null, 1);
    }
    $expires = 31536000;
    header("Cache-Control: maxage=" . $expires);
Пример #10
0
 /**
  * 生成缩略图
  * @param  [type]  $path [原图路径]
  * @param  integer $tw   [缩略图宽度]
  * @param  integer $th   [缩略图高度]
  * @return [image]        [缩略图资源]
  */
 public static function make($path, $tw = 1, $th = 1)
 {
     strpos($path, '..') === false or exit('What are you doing?');
     $srcPath = iPHP_RES_PAHT . $path;
     $thumbPath = $srcPath . '_' . $tw . 'x' . $th . '.jpg';
     if (empty($path) || !self::exists($srcPath)) {
         return self::blank();
     }
     iPHP_RES_CACHE && (self::$srcData = self::cache($thumbPath, 'get'));
     if (empty(self::$srcData)) {
         $gmagick = new Gmagick();
         $gmagick->readImage($srcPath);
         $scale = array("tw" => $tw, "th" => $th, "w" => $gmagick->getImageWidth(), "h" => $gmagick->getImageHeight());
         if ($tw > 0 && $th > 0) {
             $im = self::scale($scale);
             $gmagick->resizeImage($im['w'], $im['h'], null, 1);
             $x = $y = 0;
             $im['w'] > $im['tw'] && ($x = ceil(($im['w'] - $im['tw']) / 3));
             $im['h'] > $im['th'] && ($y = ceil(($im['h'] - $im['th']) / 3));
             $gmagick->cropImage($tw, $th, $x, $y);
         } else {
             empty($scale['th']) && ($scale['th'] = 9999999);
             $im = self::bitScale($scale);
             $gmagick->resizeImage($im['w'], $im['h'], null, 1);
         }
         header('X-Thumb-Cache: MAKE-' . $_SERVER['REQUEST_TIME']);
         self::$srcData = $gmagick->current();
         iPHP_RES_CACHE && self::cache($thumbPath, self::$srcData);
     }
 }
Пример #11
0
 public static function thumbnail($src, $tw = "0", $th = "0", $scale = true)
 {
     if (!self::$config['thumb']['enable']) {
         return;
     }
     $rs = array();
     $tw = empty($tw) ? self::$config['thumb']['width'] : (int) $tw;
     $th = empty($th) ? self::$config['thumb']['height'] : (int) $th;
     if ($tw && $th) {
         list($width, $height, $type) = getimagesize($src);
         if ($width < 1 && $height < 1) {
             $rs['width'] = $tw;
             $rs['height'] = $th;
             $rs['src'] = $src;
             return $rs;
         }
         if ($width > $tw || $height > $th) {
             $rs['src'] = $src . '_' . $tw . 'x' . $th . '.jpg';
             if (in_array('Gmagick', get_declared_classes())) {
                 $image = new Gmagick();
                 $image->readImage($src);
                 $im = self::scale(array("tw" => $tw, "th" => $th, "w" => $image->getImageWidth(), "h" => $image->getImageHeight()));
                 $image->resizeImage($im['w'], $im['h'], null, 1);
                 $image->cropImage($tw, $th, 0, 0);
                 //$image->thumbnailImage($gm_w,$gm_h);
                 $image->writeImage($rs['src']);
                 $image->destroy();
             } else {
                 $im = self::scale(array("tw" => $tw, "th" => $th, "w" => $width, "h" => $height), $scale);
                 $ret = self::imagecreate($type, $src);
                 $rs['width'] = $im['w'];
                 $rs['height'] = $im['h'];
                 if ($ret) {
                     $thumb = imagecreatetruecolor($im['w'], $im['h']);
                     imagecopyresampled($thumb, $ret, 0, 0, 0, 0, $im['w'], $im['h'], $width, $height);
                     self::image($thumb, $type, $rs['src']);
                 } else {
                     $rs['src'] = $src;
                 }
             }
         } else {
             $rs['src'] = $src;
             $rs['width'] = $width;
             $rs['height'] = $height;
         }
         return $rs;
     }
 }
Пример #12
0
 /** 
  * 生成水印
  * @param string $groundImage 
  */
 function waterImage($groundImage = '')
 {
     try {
         //获取背景图的高,宽
         if ($groundImage && is_file($groundImage)) {
             $bg = new Gmagick();
             $bg->readImage($groundImage);
             $bgHeight = $bg->getImageHeight();
             $bgWidth = $bg->getImageWidth();
         }
         //获取水印图的高,宽
         if ($this->waterImage && is_file($this->waterImage)) {
             $water = new Gmagick($this->waterImage);
             $waterHeight = $water->getImageHeight();
             $waterWidth = $water->getImageWidth();
         }
         //如果背景图的高宽小于水印图的高宽则不加水印
         if ($bgHeight < $waterHeight || $bgWidth < $waterWidth) {
             return false;
         } else {
             $isWaterImg = TRUE;
         }
         //加水印
         if ($isWaterImg) {
             $dw = new GmagickDraw();
             //加图片水印
             if (is_file($this->waterImage)) {
                 //水印位置随机
                 $waterPos = $this->getWaterPos($bgWidth, $bgHeight, $waterWidth, $waterHeight);
                 $bg->compositeImage($water, 1, $waterPos['x'], $waterPos['y']);
                 if (!$bg->writeImage($groundImage)) {
                     return FALSE;
                 }
             } else {
                 //加文字水印
                 $waterTextInfo = array('textFont' => '15', 'textColor' => '#FF0000', 'textAlpha' => 1, 'textInfo' => 'www.okooo.com');
                 $dw->setFontSize($waterTextInfo['textFont']);
                 //$dw->setFillColor($waterTextInfo['textColor']);
                 $dw->setFillOpacity(1);
                 $x = abs(130 - $bgWidth);
                 $y = abs(15 - $bgHeight);
                 $dw->annotate($x, $y, $waterTextInfo['textInfo']);
                 $dw->setTextEncoding('UTF-8');
                 $bg->drawImage($dw);
                 if (!$bg->writeImage($groundImage)) {
                     return FALSE;
                 }
             }
         }
     } catch (Exception $e) {
         Logger::getLogger('dataengine.lottery.snapshot')->apps('exception')->info(json_encode($e->getMessage()));
     }
 }