This is the GD Implementation of the PHP Thumb library.
Inheritance: extends ThumbBase
Example #1
0
 public function createWatermark($watermark, $mask_position, $mask_padding, $that)
 {
     // bring stuff from the parent class into this class...
     $this->parentInstance = $that;
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->mask_position = $mask_position;
     $width = $this->currentDimensions['width'];
     $height = $this->currentDimensions['height'];
     $watermarksize = getimagesize($watermark);
     $dest_x = $width - $watermarksize[0] - 55;
     $dest_y = $height - $watermarksize[1] - 55;
     //$watermark = imagecreatefrompng($watermark);
     $pathinfo = pathinfo($watermark);
     $var1 = $pathinfo['extension'];
     $var2 = "png";
     $var3 = "jpeg";
     $var4 = "jpg";
     $var5 = "gif";
     if (strcasecmp($var1, $var2) == 0) {
         $watermark = @imagecreatefrompng($watermark);
     } elseif (strcasecmp($var1, $var3) == 0 || strcasecmp($var1, $var4) == 0) {
         $watermark = @imagecreatefromjpeg($watermark);
     } elseif (strcasecmp($var1, $var5) == 0) {
         $watermark = @imagecreatefromgif($watermark);
     }
     switch ($mask_position) {
         case 'cc':
             // Center
             $dest_x = round(($width - $watermarksize[0]) / 2);
             $dest_y = round(($height - $watermarksize[1]) / 2);
             break;
         case 'lt':
             // Left Top
             $dest_x = $mask_padding;
             $dest_y = $mask_padding;
             break;
         case 'rt':
             // Right Top
             $dest_x = $width - $mask_padding - $watermarksize[0];
             $dest_y = $mask_padding;
             break;
         case 'lb':
             // Left Bottom
             $dest_x = $mask_padding;
             $dest_y = $height - $mask_padding - $watermarksize[1];
             break;
         case 'rb':
             // Right Bottom
             $dest_x = $width - $mask_padding - $watermarksize[0];
             $dest_y = $height - $mask_padding - $watermarksize[1];
             break;
         case 'cb':
             // Center Bottom
             $dest_x = round(($width - $watermarksize[0]) / 2);
             $dest_y = $height - $mask_padding - $watermarksize[1];
             break;
     }
     imagecopy($this->parentInstance->getOldImage(), $watermark, $dest_x, $dest_y, 0, 0, $watermarksize[0], $watermarksize[1]);
     return $that;
 }
Example #2
0
 public function resizeStretch($width, $height, &$that)
 {
     // bring stuff from the parent class into this class...
     $this->parentInstance = $that;
     $this->oldImage = $this->parentInstance->getOldImage();
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     $this->options = $this->parentInstance->getOptions();
     // make sure our arguments are valid
     if (!is_numeric($width)) {
         throw new InvalidArgumentException('$maxWidth must be numeric');
     }
     if (!is_numeric($height)) {
         throw new InvalidArgumentException('$maxHeight must be numeric');
     }
     // get the new dimensions...
     $this->newDimensions = array('newWidth' => $width, 'newHeight' => $height);
     // create the working image
     if (function_exists('imagecreatetruecolor')) {
         $this->workingImage = imagecreatetruecolor($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
     } else {
         $this->workingImage = imagecreate($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
     }
     //$this->parentInstance->preserveAlpha();
     // and create the newly sized image
     imagecopyresampled($this->workingImage, $this->oldImage, 0, 0, 0, 0, $this->newDimensions['newWidth'], $this->newDimensions['newHeight'], $this->currentDimensions['width'], $this->currentDimensions['height']);
     // update all the variables and resources to be correct
     $this->parentInstance->setOldImage($this->workingImage);
     $this->parentInstance->setCurrentDimensions($this->newDimensions);
     return $that;
 }
Example #3
0
 public function rotateJpg(&$that)
 {
     $this->parentInstance = $that;
     // Test if exif is installed
     if (!is_callable('exif_read_data')) {
         return $that;
     }
     // Exif couldn't do it's thing.  Suppressing errors on it cause it
     // does a non-exception error if it can't read the image.
     $exif = @exif_read_data($this->parentInstance->getFilename());
     // There is no orientation data, so exit
     if (empty($exif['Orientation'])) {
         return $that;
     }
     // Act on orientation info
     switch ($exif['Orientation']) {
         case 1:
             // nothing
             break;
         case 2:
             //code here
             break;
         case 3:
             // 180 rotate left
             $this->parentInstance->rotateImageNDegrees(180);
             break;
         case 4:
             // vertical flip
             //
             break;
         case 5:
             // vertical flip + 90 rotate right
             //
             break;
         case 6:
             // 90 rotate right
             $this->parentInstance->rotateImageNDegrees(-90);
             break;
         case 7:
             // horizontal flip + 90 rotate right
             //
             break;
         case 8:
             // 90 rotate left
             $this->parentInstance->rotateImageNDegrees(90);
             break;
     }
     return $that;
 }
Example #4
0
 public function createRounded($color_rounded = 'FFFFFF', $radio_rounded = 10, &$that)
 {
     // bring stuff from the parent class into this class...
     $this->parentInstance = $that;
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     // Parametros
     $this->color_rounded = $color_rounded;
     $this->radio_rounded = $radio_rounded;
     $canvas_width = $this->currentDimensions['width'];
     $canvas_height = $this->currentDimensions['height'];
     // Crea una imagen de forma cuadrada
     $corner_image = imagecreatetruecolor($this->radio_rounded, $this->radio_rounded);
     // Pinta la figura de negro
     $clear_colour = imagecolorallocate($corner_image, 0, 0, 0);
     // La pinta del color que seleccionamos
     $solid_colour = imagecolorallocate($corner_image, hexdec(substr($this->color_rounded, 0, 2)), hexdec(substr($this->color_rounded, 2, 2)), hexdec(substr($this->color_rounded, 4, 2)));
     // Crea la transparencia
     imagecolortransparent($corner_image, $clear_colour);
     imagefill($corner_image, 0, 0, $solid_colour);
     // Crea un eclipse
     imagefilledellipse($corner_image, $this->radio_rounded, $this->radio_rounded, $this->radio_rounded * 2, $this->radio_rounded * 2, $clear_colour);
     // Copia y une la imagen
     imagecopymerge($this->workingImage, $corner_image, 0, 0, 0, 0, $this->radio_rounded, $this->radio_rounded, 100);
     // La da vuelta
     $corner_image = imagerotate($corner_image, 90, 0);
     // Copia y une la imagen
     imagecopymerge($this->workingImage, $corner_image, 0, $canvas_height - $this->radio_rounded, 0, 0, $this->radio_rounded, $this->radio_rounded, 100);
     // La da vuelta
     $corner_image = imagerotate($corner_image, 90, 0);
     // Copia y une la imagen
     imagecopymerge($this->workingImage, $corner_image, $canvas_width - $this->radio_rounded, $canvas_height - $this->radio_rounded, 0, 0, $this->radio_rounded, $this->radio_rounded, 100);
     // La da vuelta
     $corner_image = imagerotate($corner_image, 90, 0);
     // Copia y une la imagen
     imagecopymerge($this->workingImage, $corner_image, $canvas_width - $this->radio_rounded, 0, 0, 0, $this->radio_rounded, $this->radio_rounded, 100);
     imagedestroy($corner_image);
     // Devuelve la imagen
     return $that;
 }
Example #5
0
 public function rotateJpg(&$that)
 {
     $this->parentInstance = $that;
     $exif = exif_read_data($this->parentInstance->getFilename());
     switch ($exif['Orientation']) {
         case 1:
             // nothing
             break;
         case 2:
             //code here
             break;
         case 3:
             // 180 rotate left
             $this->parentInstance->rotateImageNDegrees(180);
             break;
         case 4:
             // vertical flip
             //
             break;
         case 5:
             // vertical flip + 90 rotate right
             //
             break;
         case 6:
             // 90 rotate right
             $this->parentInstance->rotateImageNDegrees(-90);
             break;
         case 7:
             // horizontal flip + 90 rotate right
             //
             break;
         case 8:
             // 90 rotate left
             $this->parentInstance->rotateImageNDegrees(90);
             break;
     }
     return $that;
 }
Example #6
0
 * 
 * Licensed under the MIT License
 * Redistributions of files must retain the above copyright notice.
 * 
 * @author Ian Selby <*****@*****.**>
 * @copyright Copyright (c) 2009 Gen X Design
 * @link http://phpthumb.gxdlabs.com
 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
 * @version 3.0
 * @package PhpThumb
 * @filesource
 */
/**
 * GD Reflection Lib Plugin
 * 
 * This plugin allows you to create those fun Apple(tm)-style reflections in your images
 * 
 * @package PhpThumb
 * @subpackage Plugins
 */
class GdReflectionLib
{
    /**
	 * Instance of GdThumb passed to this class
	 * 
	 * @var GdThumb
	 */
    protected $parentInstance;
    protected $currentDimensions;
    protected $workingImage;
    protected $newImage;
    protected $options;
    public function createReflection($percent, $reflection, $white, $border, $borderColor, &$that)
    {
        // bring stuff from the parent class into this class...
        $this->parentInstance = $that;
        $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
        $this->workingImage = $this->parentInstance->getWorkingImage();
        $this->newImage = $this->parentInstance->getOldImage();
        $this->options = $this->parentInstance->getOptions();
        $width = $this->currentDimensions['width'];
        $height = $this->currentDimensions['height'];
        $reflectionHeight = intval($height * ($reflection / 100));
        $newHeight = $height + $reflectionHeight;
        $reflectedPart = $height * ($percent / 100);
        $this->workingImage = imagecreatetruecolor($width, $newHeight);
        imagealphablending($this->workingImage, true);
        $colorToPaint = imagecolorallocatealpha($this->workingImage, 255, 255, 255, 0);
Example #7
0
 public function createRounded($radius = 10, $rate = 10, &$that)
 {
     $this->parentInstance = $that;
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     imagealphablending($this->workingImage, false);
     imagesavealpha($this->workingImage, true);
     $rs_radius = $radius * $rate;
     $rs_size = $rs_radius * 2;
     $corner = imagecreatetruecolor($rs_size, $rs_size);
     imagealphablending($corner, false);
     $trans = imagecolorallocatealpha($corner, 255, 255, 255, 127);
     imagefill($corner, 0, 0, $trans);
     $positions = array(array(0, 0, 0, 0), array($rs_radius, 0, $this->currentDimensions['width'] - $radius, 0), array($rs_radius, $rs_radius, $this->currentDimensions['width'] - $radius, $this->currentDimensions['height'] - $radius), array(0, $rs_radius, 0, $this->currentDimensions['height'] - $radius));
     foreach ($positions as $pos) {
         imagecopyresampled($corner, $this->workingImage, $pos[0], $pos[1], $pos[2], $pos[3], $rs_radius, $rs_radius, $radius, $radius);
     }
     $lx = $ly = 0;
     $i = -$rs_radius;
     $y2 = -$i;
     $r_2 = $rs_radius * $rs_radius;
     for (; $i <= $y2; $i++) {
         $y = $i;
         $x = sqrt($r_2 - $y * $y);
         $y += $rs_radius;
         $x += $rs_radius;
         imageline($corner, $x, $y, $rs_size, $y, $trans);
         imageline($corner, 0, $y, $rs_size - $x, $y, $trans);
         $lx = $x;
         $ly = $y;
     }
     foreach ($positions as $i => $pos) {
         imagecopyresampled($this->workingImage, $corner, $pos[2], $pos[3], $pos[0], $pos[1], $radius, $radius, $rs_radius, $rs_radius);
     }
     return $that;
 }
Example #8
0
 public function resizeFixedSize($width, $height, $color = '#FFFFFF', &$that)
 {
     $this->parentInstance = $that;
     $this->parentInstance->resize($width, $height);
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     $this->newImage = $this->parentInstance->getOldImage();
     $this->options = $this->parentInstance->getOptions();
     $this->workingImage = imagecreatetruecolor($width, $height);
     imagealphablending($this->workingImage, true);
     $rgb = $this->hex2rgb($color, false);
     $colorToPaint = imagecolorallocatealpha($this->workingImage, $rgb[0], $rgb[1], $rgb[2], 0);
     imagefilledrectangle($this->workingImage, 0, 0, $width, $height, $colorToPaint);
     imagecopyresampled($this->workingImage, $this->newImage, intval(($width - $this->currentDimensions['width']) / 2), intval(($height - $this->currentDimensions['height']) / 2), 0, 0, $this->currentDimensions['width'], $this->currentDimensions['height'], $this->currentDimensions['width'], $this->currentDimensions['height']);
     $this->parentInstance->setOldImage($this->workingImage);
     $this->currentDimensions['width'] = $width;
     $this->currentDimensions['height'] = $height;
     $this->parentInstance->setCurrentDimensions($this->currentDimensions);
     return $that;
 }
Example #9
0
 /**
  * Pad the image
  * 
  * @param int $newWidth
  * @param int $newHeieight
  * @param int $backgroundColor
  * @return GdThumb
  */
 public function padding($newWidth, $newHeight, $backgroundColor, &$that)
 {
     // bring stuff from the parent class into this class...
     $this->parentInstance = $that;
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     $this->newImage = $this->parentInstance->getOldImage();
     $this->options = $this->parentInstance->getOptions();
     $width = $this->currentDimensions['width'];
     $height = $this->currentDimensions['height'];
     $offsetLeft = ($newWidth - $width) / 2;
     $offsetTop = ($newHeight - $height) / 2;
     $this->workingImage = imagecreatetruecolor($newWidth, $newHeight);
     $rgb = $this->hex2rgb($backgroundColor, false);
     $colorToPaint = imagecolorallocatealpha($this->workingImage, $rgb[0], $rgb[1], $rgb[2], 0);
     imagefilledrectangle($this->workingImage, 0, 0, $newWidth, $newHeight, $colorToPaint);
     imagecopy($this->workingImage, $this->newImage, $offsetLeft, $offsetTop, 0, 0, $width, $height);
     $this->parentInstance->setOldImage($this->workingImage);
     return $that;
 }
Example #10
0
 /**
  * Add logo to image
  * @param logoFileName - file name of logo image in jpg or png format
  * @param positionX - Position of logo image on X-axis ('left', 'center', 'right' or plain number)
  * @param positionY - Position of logo image on X-axis ('top', 'center', 'bottom' or plain number)
  * @param alpha - alpha value for logo merging in percent
  */
 public function addLogo($logoFileName, $positionX, $positionY, $alpha, &$that)
 {
     $logo_size = getimagesize($logoFileName);
     // bring stuff from the parent class into this class...
     $this->parentInstance = $that;
     $this->oldImage = $this->parentInstance->getOldImage();
     $this->parentInstance->setWorkingImage($this->oldImage);
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     $this->options = $this->parentInstance->getOptions();
     $src_dimension = array("x" => $this->currentDimensions['width'], "y" => $this->currentDimensions['height']);
     $logo_dimension = array("x" => $logo_size[0], "y" => $logo_size[1]);
     $center = array("x" => $src_dimension["x"] / 2 - $logo_dimension["x"] / 2, "y" => $src_dimension["y"] / 2 - $logo_dimension["y"] / 2);
     $logo_positionX["left"] = 0;
     $logo_positionX["center"] = $center["x"];
     $logo_positionX["right"] = $src_dimension["x"] - $logo_dimension["x"];
     $logo_positionY["top"] = 0;
     $logo_positionY["center"] = $center["y"];
     $logo_positionY["bottom"] = $src_dimension["y"] - $logo_dimension["y"];
     if (is_numeric($positionX)) {
         $logo_position["x"] = $positionX;
     } else {
         $logo_position["x"] = $logo_positionX[$positionX];
     }
     if (is_numeric($positionY)) {
         $logo_position["y"] = $positionY;
     } else {
         $logo_position["y"] = $logo_positionY[$positionY];
     }
     switch (exif_imagetype($logoFileName)) {
         case IMAGETYPE_JPEG:
             $logo = imagecreatefromjpeg($logoFileName);
             break;
         case IMAGETYPE_PNG:
             $logo = imagecreatefrompng($logoFileName);
             break;
     }
     imagecopymerge($this->workingImage, $logo, $logo_position["x"], $logo_position["y"], 0, 0, $logo_dimension["x"], $logo_dimension["y"], $alpha);
     return $that;
 }
Example #11
0
 /**
 ct = center top
 cc = center center
 lt = left top
 rt = right top
 lb = left bottom
 rb = right bottom
 cb = center bottom
 */
 public function createWatermark($mask_file, $mask_position = 'cc', $mask_padding = 0, $that)
 {
     // bring stuff from the parent class into this class...
     $this->parentInstance = $that;
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     $this->newImage = $this->parentInstance->getOldImage();
     $this->options = $this->parentInstance->getOptions();
     $this->mask_file = $mask_file;
     $this->mask_position = $mask_position;
     $this->mask_padding = $mask_padding;
     $canvas_width = $this->currentDimensions['width'];
     $canvas_height = $this->currentDimensions['height'];
     if ($canvas_width <= 200 || $canvas_height <= 200) {
         return $that;
     }
     list($stamp_width, $stamp_height, $stamp_type, $stamp_attr) = getimagesize($mask_file);
     switch ($stamp_type) {
         case 1:
             $stamp_image = imagecreatefromgif($mask_file);
             break;
         case 2:
             @ini_set('gd.jpeg_ignore_warning', 1);
             $stamp_image = imagecreatefromjpeg($mask_file);
             break;
         case 3:
             $stamp_image = imagecreatefrompng($mask_file);
             break;
     }
     imagealphablending($this->workingImage, true);
     if ($stamp_width > $canvas_width || $stamp_height > $canvas_height) {
         // some simple resize math
         //$water_resize_factor = round($canvas_width / $stamp_width);
         $water_resize_factor = 0.5;
         $new_mask_width = $stamp_width * $water_resize_factor;
         $new_mask_height = $stamp_height * $water_resize_factor;
         $mask_padding = $mask_padding * $water_resize_factor;
         // the new watermark creation takes place starting from here
         $new_mask_image = imagecreatetruecolor($new_mask_width, $new_mask_height);
         // imagealphablending is important in order to keep, our png image (the watewrmark) transparent
         imagealphablending($new_mask_image, false);
         imagecopyresampled($new_mask_image, $stamp_image, 0, 0, 0, 0, $new_mask_width, $new_mask_height, $stamp_width, $stamp_height);
         // assign the new values to the old variables
         $stamp_width = $new_mask_width;
         $stamp_height = $new_mask_height;
         $stamp_image = $new_mask_image;
     }
     switch ($mask_position) {
         case 'ct':
             // Center top
             $start_width = round(($canvas_width - $stamp_width) / 2);
             $start_height = $mask_padding;
             break;
         case 'cc':
             // Center
             $start_width = round(($canvas_width - $stamp_width) / 2);
             $start_height = round(($canvas_height - $stamp_height) / 2);
             break;
         case 'cb':
             // Center Bottom
             $start_width = round(($canvas_width - $stamp_width) / 2);
             $start_height = $canvas_height - $mask_padding - $stamp_height;
             break;
         case 'lt':
             // Left Top
             $start_width = $mask_padding;
             $start_height = $mask_padding;
             break;
         case 'lb':
             // Left Bottom
             $start_width = $mask_padding;
             $start_height = $canvas_height - $mask_padding - $stamp_height;
             break;
         case 'rt':
             // Right Top
             $start_width = $canvas_width - $mask_padding - $stamp_width;
             $start_height = $mask_padding;
             break;
         case 'rb':
             // Right Bottom
             $start_width = $canvas_width - $mask_padding - $stamp_width;
             $start_height = $canvas_height - $mask_padding - $stamp_height;
             break;
     }
     imagecopy($this->workingImage, $stamp_image, $start_width, $start_height, 0, 0, $stamp_width, $stamp_height);
     imagedestroy($stamp_image);
     return $that;
 }
Example #12
0
 public function __toString()
 {
     return parent::getImageAsString();
 }
Example #13
0
 /**
  * Applique un filtre à une image
  * @param string $filterType
  * @param array $filterArg
  * @param void $that
  * @throws InvalidArgumentException
  * @throws RuntimeException
  */
 public function createFilterImage($filterType, $filterArg = false, &$that)
 {
     // bring stuff from the parent class into this class...
     $this->parentInstance = $that;
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     $width = $this->currentDimensions['width'];
     $height = $this->currentDimensions['height'];
     //Filter Type
     $this->filterType = $filterType;
     //Argument du filtre
     $this->filterArg = $filterArg;
     //Test la présence de imagefilter
     if (!function_exists('imagefilter')) {
         throw new RuntimeException('Your version of GD does not support image filters.');
     }
     /**
      * Vérifie si la clé existe dans le tableau pour retourner le filtre adéquate
      */
     if (array_key_exists($filterType, self::$filter)) {
         if (!is_numeric(self::$filter[$filterType])) {
             throw new InvalidArgumentException('$filter must be numeric');
         } else {
             $filter = self::$filter[$filterType];
         }
     }
     /**
      * Si le premier paramètre est une chaine
      */
     if (is_string($this->filterType)) {
         switch ($this->filterType) {
             case 'brightness':
                 if (count($this->filterArg) != 1) {
                     throw new Exception('brightness arg1 is not define');
                 } else {
                     $this->workingFilter($this->workingImage, $filter, $this->filterArg);
                 }
                 break;
             case 'contrast':
                 if (count($this->filterArg) != 1) {
                     throw new Exception('contrast arg1 is not define');
                 } else {
                     $this->workingFilter($this->workingImage, $filter, $this->filterArg);
                 }
                 break;
             case 'colorize':
                 if (count($this->filterArg) != 3) {
                     throw new Exception('colorize arg1,arg2,arg3 is not define');
                 } else {
                     $this->workingFilter($this->workingImage, $filter, $this->filterArg);
                 }
                 break;
             case 'smooth':
                 if (count($this->filterArg) != 1) {
                     throw new Exception('smooth arg1 is not define');
                 } else {
                     $this->workingFilter($this->workingImage, $filter, $this->filterArg);
                 }
                 break;
             case 'pixelate':
                 if (count($this->filterArg) != 2) {
                     throw new Exception('pixelate arg1,arg2 is not define');
                 } else {
                     $this->workingFilter($this->workingImage, $filter, $this->filterArg);
                 }
                 break;
             case 'sepia':
                 if (is_array($this->filterArg)) {
                     $arg = $this->filterArg;
                 } else {
                     $arg = array(90, 60, 30);
                 }
                 if (count($arg) != 3) {
                     throw new Exception('sepia : colorize arg1,arg2,arg3 is not define');
                 } else {
                     $this->workingFilter($this->workingImage, self::$filter['grayscale']);
                     //$this->workingFilter($this->workingImage, self::$filter['brightness'], array(-20));
                     $this->workingFilter($this->workingImage, self::$filter['colorize'], $arg);
                 }
                 break;
             default:
                 $this->workingFilter($this->workingImage, $filter);
                 break;
         }
     } else {
         //Si le premier paramètre est de type numérique
         if (!is_numeric($this->filterType)) {
             throw new InvalidArgumentException('$filter must be numeric');
         } else {
             $this->workingFilter($this->workingImage, $this->filterType, $this->filterArg);
         }
     }
     return $that;
 }
Example #14
0
 public function createWatermark($mask_file, $mask_position = 'cc', $mask_padding = 0, $that)
 {
     // bring stuff from the parent class into this class...
     $this->parentInstance = $that;
     $this->currentDimensions = $this->parentInstance->getCurrentDimensions();
     $this->workingImage = $this->parentInstance->getWorkingImage();
     $this->newImage = $this->parentInstance->getOldImage();
     $this->options = $this->parentInstance->getOptions();
     $this->mask_file = $mask_file;
     $this->mask_position = $mask_position;
     $this->mask_padding = $mask_padding;
     $canvas_width = $this->currentDimensions['width'];
     $canvas_height = $this->currentDimensions['height'];
     list($logo_width, $logo_height, $logo_type, $logo_attr) = getimagesize($mask_file);
     switch ($logo_type) {
         case 1:
             $logo_image = imagecreatefromgif($mask_file);
             break;
         case 2:
             @ini_set('gd.jpeg_ignore_warning', 1);
             $logo_image = imagecreatefromjpeg($mask_file);
             break;
         case 3:
             $logo_image = imagecreatefrompng($mask_file);
             break;
     }
     imagealphablending($this->workingImage, true);
     switch ($mask_position) {
         // Random
         case 'rd':
             $start_width = round(mt_rand($mask_padding, $canvas_width - $logo_width - $mask_padding));
             $start_height = round(mt_rand($mask_padding, $canvas_height - $logo_height - $mask_padding));
             break;
             // Center top
         // Center top
         case 'ct':
         case 'tc':
             $start_width = round(($canvas_width - $logo_width) / 2);
             $start_height = $mask_padding;
             break;
             // Center middle
         // Center middle
         case 'mc':
         case 'cm':
         case 'cc':
             $start_width = round(($canvas_width - $logo_width) / 2);
             $start_height = round(($canvas_height - $logo_height) / 2);
             break;
             // Center bottom
         // Center bottom
         case 'cb':
         case 'bc':
             $start_width = round(($canvas_width - $logo_width) / 2);
             $start_height = $canvas_height - $mask_padding - $logo_height;
             break;
             // Left top
         // Left top
         case 'lt':
         case 'tl':
             $start_width = $mask_padding;
             $start_height = $mask_padding;
             break;
             // Left center
         // Left center
         case 'lc':
         case 'cl':
             $start_width = $mask_padding;
             $start_height = round(($canvas_height - $logo_height) / 2);
             break;
             // Left bottom
         // Left bottom
         case 'lb':
         case 'bl':
             $start_width = $mask_padding;
             $start_height = $canvas_height - $mask_padding - $logo_height;
             break;
             // Right top
         // Right top
         case 'rt':
         case 'tr':
             $start_width = $canvas_width - $mask_padding - $logo_width;
             $start_height = $mask_padding;
             break;
             // Right center
         // Right center
         case 'rc':
         case 'cr':
             $start_width = $canvas_width - $mask_padding - $logo_width;
             $start_height = round(($canvas_height - $logo_height) / 2);
             break;
             // Right bottom
         // Right bottom
         case 'rb':
         case 'br':
         default:
             $start_width = $canvas_width - $logo_width - $mask_padding;
             $start_height = $canvas_height - $logo_height - $mask_padding;
             break;
     }
     imagecopy($this->workingImage, $logo_image, $start_width, $start_height, 0, 0, $logo_width, $logo_height);
     imagedestroy($logo_image);
     return $that;
 }
Example #15
0
 public static function createThumb($source, $dest = null, $width = 200, $height = 160, $mode = 'resize')
 {
     if (!class_exists('ThumbBase')) {
         require_once JPATH_SITE . '/plugins/system/jvhelper/libs/ThumbBase.inc.php';
     }
     if (!class_exists('GdThumb')) {
         require_once JPATH_SITE . '/plugins/system/jvhelper/libs/GdThumb.inc.php';
     }
     if (!$dest) {
         $dest = JPATH_SITE . '/images/jvthumb';
     }
     $size = @getimagesize($source);
     if (!is_array($size)) {
         return $source;
     }
     $replace = JURI::base(true) . '/';
     if (strpos($source, $replace) === 0) {
         $source = substr($source, strlen($replace));
     }
     if (preg_match('#http(s?):\\/\\/#', $source) && $source) {
         if (stripos($size['mime'], 'image') === 0) {
             $extension = substr($size['mime'], 6);
             if ($extension == 'jpeg') {
                 $extension = 'jpg';
             }
             $info = array('extension' => $extension, 'filename' => substr(base64_encode(json_encode($size)), 0, 10));
         } else {
             return $source;
         }
     } else {
         $source = JPATH_SITE . '/' . $source;
         $info = pathinfo($source);
     }
     // Resize path
     $path = $dest . "/{$mode}_{$width}_{$height}_{$info['filename']}.{$info['extension']}";
     if (!is_dir(dirname($path))) {
         JFolder::create(dirname($path));
         $index = "<html><body></body></html>";
         if (!JFile::write($path . '/' . 'index.html', $index)) {
             return;
         }
     }
     if (!is_file($path)) {
         // Resize
         $thumb = new GdThumb($source, array('jpegQuality' => 80));
         if ($mode == 'resize') {
             $thumb->resize($width, $height);
         }
         if ($mode == 'crop') {
             $thumb->cropFromCenter($width, $height);
         }
         $thumb->save($path, $info['extension']);
     }
     return self::toURL($path);
 }
Example #16
0
 protected function _writeResized(GdThumb $resized, $type = null)
 {
     $resized->save($this->getOutputPath(), $type);
     return $this->getOutputPath();
 }
Example #17
0
 /**
  * Get the image data
  *
  * @return string Image data
  */
 public function get()
 {
     return $this->thumb->getImageAsString();
 }
Example #18
0
 public static function createThumb($source, $dest, $width, $height, $mode)
 {
     $size = @getimagesize($source);
     if (!is_array($size)) {
         return $source;
     }
     $replace = JURI::base(true) . '/';
     if (strpos($source, $replace) === 0) {
         $source = substr($source, strlen($replace));
     }
     if (preg_match('#http(s?):\\/\\/#', $source) && $source) {
         if (stripos($size['mime'], 'image') === 0) {
             $extension = substr($size['mime'], 6);
             if ($extension == 'jpeg') {
                 $extension = 'jpg';
             }
             $info = array('extension' => $extension, 'filename' => substr(base64_encode(json_encode($size)), 0, 10));
         } else {
             return $source;
         }
     } else {
         $source = JPATH_SITE . '/' . $source;
         $info = pathinfo($source);
     }
     // Resize path
     $path = $dest . "/{$mode}_{$width}_{$info['filename']}.{$info['extension']}";
     if (!is_dir(dirname($path))) {
         JFolder::create(dirname($path));
         $index = "<html><body></body></html>";
         if (!JFile::write($path . '/' . 'index.html', $index)) {
             return;
         }
     }
     if (!is_file($path)) {
         // Resize
         if ($mode == 'original') {
             JFile::copy($source, $path);
             return self::toURL($path);
         }
         $thumb = new GdThumb($source, array('jpegQuality' => 90));
         if ($mode == 'resize') {
             $thumb->resize($width, $height);
         }
         if ($mode == 'crop') {
             $thumb->cropFromCenter($width, $height);
         }
         $thumb->save($path, $info['extension']);
     }
     return self::toURL($path);
 }