getWorkingImage() публичный Метод

Returns $workingImage.
См. также: GdThumb::$workingImage
public getWorkingImage ( )
Пример #1
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;
 }
 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);
     imagefilledrectangle($this->workingImage, 0, 0, $width, $newHeight, $colorToPaint);
     imagecopyresampled($this->workingImage, $this->newImage, 0, 0, 0, $reflectedPart, $width, $reflectionHeight, $width, $height - $reflectedPart);
     $this->imageFlipVertical();
     imagecopy($this->workingImage, $this->newImage, 0, 0, 0, 0, $width, $height);
     imagealphablending($this->workingImage, true);
     for ($i = 0; $i < $reflectionHeight; $i++) {
         $colorToPaint = imagecolorallocatealpha($this->workingImage, 255, 255, 255, ($i / $reflectionHeight * -1 + 1) * $white);
         imagefilledrectangle($this->workingImage, 0, $height + $i, $width, $height + $i, $colorToPaint);
     }
     if ($border == true) {
         $rgb = $this->hex2rgb($borderColor, false);
         $colorToPaint = imagecolorallocate($this->workingImage, $rgb[0], $rgb[1], $rgb[2]);
         imageline($this->workingImage, 0, 0, $width, 0, $colorToPaint);
         //top line
         imageline($this->workingImage, 0, $height, $width, $height, $colorToPaint);
         //bottom line
         imageline($this->workingImage, 0, 0, 0, $height, $colorToPaint);
         //left line
         imageline($this->workingImage, $width - 1, 0, $width - 1, $height, $colorToPaint);
         //right line
     }
     if ($this->parentInstance->getFormat() == 'PNG') {
         $colorTransparent = imagecolorallocatealpha($this->workingImage, $this->options['alphaMaskColor'][0], $this->options['alphaMaskColor'][1], $this->options['alphaMaskColor'][2], 0);
         imagefill($this->workingImage, 0, 0, $colorTransparent);
         imagesavealpha($this->workingImage, true);
     }
     $this->parentInstance->setOldImage($this->workingImage);
     $this->currentDimensions['width'] = $width;
     $this->currentDimensions['height'] = $newHeight;
     $this->parentInstance->setCurrentDimensions($this->currentDimensions);
     return $that;
 }
Пример #3
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;
 }
Пример #4
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;
 }
Пример #5
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;
 }
Пример #6
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;
 }
Пример #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;
 }
Пример #8
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;
 }
Пример #9
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;
 }
Пример #10
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;
 }