getOptions() public method

Returns $options.
See also: GdThumb::$options
public getOptions ( )
Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 /**
  * Resize and crop
  *
  * @param integer $width
  * @param integer $height
  * @return $this
  */
 public function crop($width, $height)
 {
     // GdThumb will not enforce the requested aspect ratio if the image is too
     // small, so we manually calculate what the size should be if the aspect
     // ratio is preserved.
     $options = $this->thumb->getOptions();
     if (empty($options['resizeUp'])) {
         $size = $this->thumb->getCurrentDimensions();
         $ratio = $width / $height;
         if ($size['width'] < $width) {
             $width = $size['width'];
             $height = $size['width'] / $ratio;
         }
         if ($size['height'] < $height) {
             $height = $size['height'];
             $width = $size['height'] * $ratio;
         }
     }
     // Do a normal adpative resize
     $this->thumb->adaptiveResize($width, $height);
     return $this;
 }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
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;
 }