Example #1
0
 /**
  * Method to apply a background color to an image resource.
  *
  * @param   array  $options  An array of options for the filter.
  *                           color  Background matte color
  *
  * @return  void
  *
  * @since   3.4
  * @throws  InvalidArgumentException
  * @deprecated  5.0  Use Joomla\Image\Filter\Backgroundfill::execute() instead
  */
 public function execute(array $options = array())
 {
     // Validate that the color value exists and is an integer.
     if (!isset($options['color'])) {
         throw new InvalidArgumentException('No color value was given. Expected string or array.');
     }
     $colorCode = !empty($options['color']) ? $options['color'] : null;
     // Get resource dimensions
     $width = imagesX($this->handle);
     $height = imagesY($this->handle);
     // Sanitize color
     $rgba = $this->sanitizeColor($colorCode);
     // Enforce alpha on source image
     if (imageIsTrueColor($this->handle)) {
         imageAlphaBlending($this->handle, false);
         imageSaveAlpha($this->handle, true);
     }
     // Create background
     $bg = imageCreateTruecolor($width, $height);
     imageSaveAlpha($bg, empty($rgba['alpha']));
     // Allocate background color.
     $color = imageColorAllocateAlpha($bg, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
     // Fill background
     imageFill($bg, 0, 0, $color);
     // Apply image over background
     imageCopy($bg, $this->handle, 0, 0, 0, 0, $width, $height);
     // Move flattened result onto curent handle.
     // If handle was palette-based, it'll stay like that.
     imageCopy($this->handle, $bg, 0, 0, 0, 0, $width, $height);
     // Free up memory
     imageDestroy($bg);
     return;
 }
Example #2
0
 function compress($Media, $value)
 {
     switch ($Media->mimeType) {
         case 'image/jpeg':
             $this->_compression = (int) (100 - $value * 10);
             break;
         case 'image/png':
             if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
                 $this->_compression = (int) $value;
             }
             if (version_compare(PHP_VERSION, '5.1.3', '>=')) {
                 $filter = $value * 10 % 10;
                 $map = array(0 => PNG_FILTER_NONE, 1 => PNG_FILTER_SUB, 2 => PNG_FILTER_UP, 3 => PNG_FILTER_AVG, 4 => PNG_FILTER_PAETH);
                 if (array_key_exists($filter, $map)) {
                     $this->_pngFilter = $map[$filter];
                 } elseif ($filter == 5) {
                     if (intval($value) <= 5 && imageIsTrueColor($Media->resources['gd'])) {
                         $this->_pngFilter = PNG_ALL_FILTERS;
                     } else {
                         $this->_pngFilter = PNG_NO_FILTER;
                     }
                 } else {
                     $this->_pngFilter = PNG_ALL_FILTERS;
                 }
             }
             break;
     }
     return true;
 }
Example #3
0
 public function compress($value)
 {
     switch ($this->_format) {
         case 'jpeg':
             $this->_compression = (int) (100 - $value * 10);
             break;
         case 'png':
             $this->_compression = (int) $value;
             $filter = $value * 10 % 10;
             $map = [0 => PNG_FILTER_NONE, 1 => PNG_FILTER_SUB, 2 => PNG_FILTER_UP, 3 => PNG_FILTER_AVG, 4 => PNG_FILTER_PAETH];
             if (array_key_exists($filter, $map)) {
                 $this->_pngFilter = $map[$filter];
             } elseif ($filter == 5) {
                 if (intval($value) <= 5 && imageIsTrueColor($this->_object)) {
                     $this->_pngFilter = PNG_ALL_FILTERS;
                 } else {
                     $this->_pngFilter = PNG_NO_FILTER;
                 }
             } else {
                 $this->_pngFilter = PNG_ALL_FILTERS;
             }
             break;
     }
     return true;
 }
         $im = imageCreateFromJPEG($image_path);
         $image_create_fun = 'imageJPEG';
         break;
     case 'GIF':
         $im = imageCreateFromGIF($image_path);
         $image_create_fun = 'imageGIF';
         break;
     case 'PNG':
         $im = imageCreateFromPNG($image_path);
         $image_create_fun = 'imagePNG';
 }
 if ($_POST['image_type'] !== 'original') {
     $image_create_fun = 'image' . $_POST['image_type'];
 }
 if ($_POST['black_white'] == 'yes') {
     if (imageIsTrueColor($im)) {
         imagetruecolortopalette($im, false, 256);
     }
     for ($i = 0, $colors = imageColorsTotal($im); $i < $colors; $i++) {
         $color = imageColorsForIndex($im, $i);
         $gray = round($color['red'] * 0.229 + $color['green'] * 0.587 + $color['red'] * 0.114);
         imageColorSet($im, $i, $gray, $gray, $gray);
     }
 }
 $file_name = '';
 $extention = $_POST['image_type'];
 if ($_POST['image_type'] == 'jpeg') {
     $extention = 'jpg';
 }
 if ($_POST['image_type'] == 'original') {
     $file_name = $_FILES['image']['name'];