/**
  * Creates an image for every code character.
  */
 protected function createCharImages()
 {
     $counter = 0;
     for ($i = 0, $j = strlen($this->codeWord); $i < $j; $i++) {
         $char = $this->codeWord[$i];
         $tempImageWidth = $this->fontSize * 2;
         $tempImageHeight = $this->fontSize + 40;
         // create image
         $tempImage = imageCreate($tempImageWidth, $tempImageHeight);
         $tempColor = imageColorAllocate($tempImage, $this->color2['red'], $this->color2['green'], $this->color2['blue']);
         imageColorTransparent($tempImage, $tempColor);
         // set font color
         $fontColor = imageColorAllocate($tempImage, $this->fontColor['red'], $this->fontColor['green'], $this->fontColor['blue']);
         // write text
         imageTtfText($tempImage, $this->fontSize, 0, 10, $this->fontSize + mt_rand(25, 30), $fontColor, $this->fontFace, $char);
         // morph text
         if (CAPTCHA_FONT_MORPH) {
             $tempImageHeight = 120;
             $tempImage2 = imageCreate($tempImageWidth, 120);
             $tempColor = imageColorAllocate($tempImage2, $this->color2['red'], $this->color2['green'], $this->color2['blue']);
             imageColorTransparent($tempImage2, $tempColor);
             $divisor = mt_rand(6, 7);
             $quotient = mt_rand(4, 6);
             $method = mt_rand(0, 1);
             // morph text on x-axis
             if ($method == 0) {
                 for ($y = 1; $y <= $tempImageHeight; $y++) {
                     $posX = sin($y / $divisor) * $quotient;
                     imageCopyMerge($tempImage2, $tempImage, $posX, $y, 0, $y, $tempImageWidth, 1, 100);
                 }
             }
             // morph text on y-axis
             if ($method == 1) {
                 for ($x = 1; $x <= $tempImageWidth; $x++) {
                     $posY = sin($x / $divisor) * $quotient;
                     imageCopyMerge($tempImage2, $tempImage, $x, $posY, $x, 0, 1, $tempImageHeight, 100);
                 }
             }
             $image = $tempImage2;
         } else {
             $image = $tempImage;
         }
         // get text width and height
         $positionX = 0;
         for ($x = $tempImageWidth - 1; $x > 0; $x--) {
             for ($y = $tempImageHeight - 1; $y > 0; $y--) {
                 $color = imageColorAt($image, $x, $y);
                 $colorArray = imageColorsForIndex($image, $color);
                 if ($colorArray['red'] == $this->fontColor['red'] && $colorArray['green'] == $this->fontColor['green'] && $colorArray['blue'] == $this->fontColor['blue']) {
                     $positionX = $x;
                     $x = 0;
                     $y = 0;
                     break;
                 }
             }
         }
         $width = $positionX + 10;
         $height = 100;
         // create final char image
         $this->chars[$counter] = imageCreate($width, $height);
         $color2 = imageColorAllocate($this->chars[$counter], $this->color2['red'], $this->color2['green'], $this->color2['blue']);
         imageColorTransparent($this->chars[$counter], $color2);
         imageCopyMerge($this->chars[$counter], $image, 5, 5, 0, 0, $width, $tempImageHeight, 100);
         $this->charWidth[$counter] = $width;
         // destroy temp images
         imageDestroy($tempImage);
         if (CAPTCHA_FONT_MORPH) {
             imageDestroy($tempImage2);
         }
         $counter++;
     }
 }
Example #2
0
function Colorize($IMG, $RGB)
{
    imageTrueColorToPalette($IMG, true, 256);
    $numColors = imageColorsTotal($IMG);
    for ($x = 0; $x < $numColors; $x++) {
        list($r, $g, $b) = array_values(imageColorsForIndex($IMG, $x));
        $grayscale = ($r + $g + $b) / 3 / 0xff;
        imageColorSet($IMG, $x, $grayscale * $RGB[0], $grayscale * $RGB[1], $grayscale * $RGB[2]);
    }
}
Example #3
0
 static function colorize($image, $rgb_code)
 {
     imageTrueColorToPalette($image, true, 256);
     $num_colors = imageColorsTotal($image);
     for ($x = 0; $x < $num_colors; $x++) {
         list($r, $g, $b) = array_values(imageColorsForIndex($image, $x));
         $gray_scale = ($r + $g + $b) / 3 / 0xff;
         imageColorSet($image, $x, $gray_scale * $rgb_code[0], $gray_scale * $rgb_code[1], $gray_scale * $rgb_code[2]);
     }
 }
Example #4
0
 public function image_colorize($rgb)
 {
     imageTrueColorToPalette($this->imageResized, true, 256);
     $numColors = imageColorsTotal($this->imageResized);
     for ($x = 0; $x < $numColors; $x++) {
         list($r, $g, $b) = array_values(imageColorsForIndex($this->imageResized, $x));
         // calculate grayscale in percent
         $grayscale = ($r + $g + $b) / 3 / 0xff;
         imageColorSet($this->imageResized, $x, $grayscale * $rgb[0], $grayscale * $rgb[1], $grayscale * $rgb[2]);
     }
     return true;
 }
Example #5
0
 /**
  * Method to resize the current image.
  *
  * @param   mixed    $width        The width of the resized image in pixels or a percentage.
  * @param   mixed    $height       The height of the resized image in pixels or a percentage.
  * @param   bool     $createNew    If true the current image will be cloned, resized and returned; else
  * the current image will be resized and returned.
  * @param   integer  $scaleMethod  Which method to use for scaling
  *
  * @return  JImage
  *
  * @since   11.3
  * @throws  LogicException
  */
 public function resize($width, $height, $createNew = true, $scaleMethod = JImage::SCALE_INSIDE)
 {
     // Make sure the resource handle is valid.
     if (!$this->isLoaded()) {
         throw new LogicException('No valid image was loaded.');
     }
     // Sanitize width.
     $width = $this->sanitizeWidth($width, $height);
     // Sanitize height.
     $height = $this->sanitizeHeight($height, $width);
     // Prepare the dimensions for the resize operation.
     $dimensions = $this->prepareDimensions($width, $height, $scaleMethod);
     // Create the new truecolor image handle.
     $handle = imagecreatetruecolor($dimensions->width, $dimensions->height);
     // Allow transparency for the new image handle.
     imagealphablending($handle, false);
     imagesavealpha($handle, true);
     if ($this->isTransparent()) {
         // Get the transparent color values for the current image.
         $rgba = imageColorsForIndex($this->handle, imagecolortransparent($this->handle));
         $color = imageColorAllocate($this->handle, $rgba['red'], $rgba['green'], $rgba['blue']);
         // Set the transparent color values for the new image.
         imagecolortransparent($handle, $color);
         imagefill($handle, 0, 0, $color);
         imagecopyresized($handle, $this->handle, 0, 0, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     } else {
         imagecopyresampled($handle, $this->handle, 0, 0, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     }
     // If we are resizing to a new image, create a new JImage object.
     if ($createNew) {
         // @codeCoverageIgnoreStart
         $new = new JImage($handle);
         return $new;
         // @codeCoverageIgnoreEnd
     } else {
         $this->handle = $handle;
         return $this;
     }
 }
Example #6
0
 function draw_slices($x, $y, $angles, $colors)
 {
     $pie_count = count($angles);
     $PIE_THICKNESS = $this->diameter * 0.075;
     for ($j = $this->center_y + $PIE_THICKNESS; $j > $this->center_y; $j--) {
         for ($from = 0, $p = 0; $p < $pie_count; $p++, $from = $to) {
             $to = $from + $angles[$p];
             if ($to > 360) {
                 $to = 360;
             }
             if ($to == $from) {
                 continue;
             }
             $color = $colors[$p];
             $orig_colors = imageColorsForIndex($this->im, $color);
             $dark_red = $orig_colors['red'] > 30 ? $orig_colors['red'] - 30 : $orig_colors['red'];
             $dark_green = $orig_colors['green'] > 30 ? $orig_colors['green'] - 30 : $orig_colors['green'];
             $dark_blue = $orig_colors['blue'] > 30 ? $orig_colors['blue'] - 30 : $orig_colors['blue'];
             $new_color = ImageColorAllocate($this->im, $dark_red, $dark_green, $dark_blue);
             ImageFilledArc($this->im, $this->center_x, $j, $this->diameter, $this->diameter, $from, $to, $new_color, IMG_ARC_PIE);
         }
     }
     for ($from = 0, $p = 0; $p < $pie_count; $p++, $from = $to) {
         $to = $from + $angles[$p];
         $color = $colors[$p];
         if ($to > 360) {
             $to = 360;
         }
         if ($to == $from) {
             continue;
         }
         ImageFilledArc($this->im, $this->center_x, $this->center_y, $this->diameter, $this->diameter, $from, $to, $color, IMG_ARC_PIE);
         $from += $angles[$p];
     }
 }
Example #7
0
 /**
  * Method to resize the current image.
  *
  * @param   mixed    $width        The width of the resized image in pixels or a percentage.
  * @param   mixed    $height       The height of the resized image in pixels or a percentage.
  * @param   boolean  $createNew    If true the current image will be cloned, resized and returned; else
  *                                 the current image will be resized and returned.
  * @param   integer  $scaleMethod  Which method to use for scaling
  *
  * @return  KunenaImage
  *
  * @since   11.3
  * @throws  LogicException
  */
 public function resize($width, $height, $createNew = true, $scaleMethod = self::SCALE_INSIDE)
 {
     $config = KunenaFactory::getConfig();
     switch ($config->avatarresizemethod) {
         case '0':
             $resizemethod = 'imagecopyresized';
             break;
         case '1':
             $resizemethod = 'imagecopyresampled';
             break;
         default:
             $resizemethod = 'self::imageCopyResampledBicubic';
             break;
     }
     // Make sure the resource handle is valid.
     if (!$this->isLoaded()) {
         throw new LogicException('No valid image was loaded.');
     }
     // Sanitize width.
     $width = $this->sanitizeWidth($width, $height);
     // Sanitize height.
     $height = $this->sanitizeHeight($height, $width);
     // Prepare the dimensions for the resize operation.
     $dimensions = $this->prepareDimensions($width, $height, $scaleMethod);
     // Instantiate offset.
     $offset = new stdClass();
     $offset->x = $offset->y = 0;
     // Get truecolor handle
     $handle = imagecreatetruecolor($dimensions->width, $dimensions->height);
     // Center image if needed and create the new truecolor image handle.
     if ($scaleMethod == self::SCALE_FIT) {
         // Get the offsets
         $offset->x = round(($width - $dimensions->width) / 2);
         $offset->y = round(($height - $dimensions->height) / 2);
         // Make image transparent, otherwise cavas outside initial image would default to black
         if (!$this->isTransparent()) {
             $transparency = imagecolorAllocateAlpha($this->handle, 0, 0, 0, 127);
             imagecolorTransparent($this->handle, $transparency);
         }
     }
     $imgProperties = self::getImageFileProperties($this->getPath());
     if ($imgProperties->mime == MIME_GIF) {
         $trnprt_indx = imagecolortransparent($this->handle);
         if ($trnprt_indx >= 0 && $trnprt_indx < imagecolorstotal($this->handle)) {
             $trnprt_color = imagecolorsforindex($this->handle, $trnprt_indx);
             $trnprt_indx = imagecolorallocate($handle, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
             imagefill($handle, 0, 0, $trnprt_indx);
             imagecolortransparent($handle, $trnprt_indx);
         }
     } elseif ($imgProperties->mime == MIME_PNG) {
         imagealphablending($handle, false);
         imagesavealpha($handle, true);
         if ($this->isTransparent()) {
             $transparent = imagecolorallocatealpha($this->handle, 255, 255, 255, 127);
             imagefilledrectangle($this->handle, 0, 0, $width, $height, $transparent);
         }
     }
     if ($this->isTransparent()) {
         $trnprt_indx = imagecolortransparent($this->handle);
         if ($trnprt_indx >= 0 && $trnprt_indx < imagecolorstotal($this->handle)) {
             // Get the transparent color values for the current image.
             $rgba = imageColorsForIndex($this->handle, imagecolortransparent($this->handle));
             $color = imageColorAllocateAlpha($handle, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
         } else {
             $color = imageColorAllocateAlpha($handle, 255, 255, 255, 127);
         }
         // Set the transparent color values for the new image.
         imagecolortransparent($handle, $color);
         imagefill($handle, 0, 0, $color);
         imagecopyresized($handle, $this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     } else {
         call_user_func_array($resizemethod, array(&$handle, &$this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight()));
     }
     // If we are resizing to a new image, create a new KunenaImage object.
     if ($createNew) {
         // @codeCoverageIgnoreStart
         $new = new KunenaImage($handle);
         return $new;
         // @codeCoverageIgnoreEnd
     } else {
         // Free the memory from the current handle
         $this->destroy();
         $this->handle = $handle;
         return $this;
     }
 }
 function crop($width, $height, $left, $top, $createNew = true, $scaleMethod = CKunenaImage::SCALE_INSIDE)
 {
     // Make sure the file handle is valid.
     if (!is_resource($this->_handle) || get_resource_type($this->_handle) != 'gd') {
         $this->setError(JText::_('COM_KUNENA_ATTACHMENT_ERROR_INVALID_FILE_HANDLE'));
         return false;
     }
     // Sanitize width.
     $width = $width === null ? $height : $width;
     if (preg_match('/^[0-9]+(\\.[0-9]+)?\\%$/', $width)) {
         $width = intval(round($this->getWidth() * floatval(str_replace('%', '', $width)) / 100));
     } else {
         $width = intval(round(floatval($width)));
     }
     // Sanitize height.
     $height = $height === null ? $width : $height;
     if (preg_match('/^[0-9]+(\\.[0-9]+)?\\%$/', $height)) {
         $height = intval(round($this->getHeight() * floatval(str_replace('%', '', $height)) / 100));
     } else {
         $height = intval(round(floatval($height)));
     }
     // Sanitize left.
     $left = intval(round(floatval($left)));
     // Sanitize top.
     $top = intval(round(floatval($top)));
     // Create the new truecolor image handle.
     $handle = imagecreatetruecolor($width, $height);
     // Allow transparency for the new image handle.
     imagealphablending($handle, true);
     imagesavealpha($handle, true);
     if ($this->isTransparent()) {
         // Get the transparent color values for the current image.
         $rgba = imageColorsForIndex($this->_handle, imagecolortransparent($this->_handle));
         $color = imageColorAllocate($this->_handle, $rgba['red'], $rgba['green'], $rgba['blue']);
         // Set the transparent color values for the new image.
         imagecolortransparent($handle, $color);
         imagefill($handle, 0, 0, $color);
         imagecopyresized($handle, $this->_handle, 0, 0, $left, $top, $width, $height, $width, $height);
     } else {
         imagecopyresampled($handle, $this->_handle, 0, 0, $left, $top, $width, $height, $width, $height);
     }
     // If we are cropping to a new image, create a new CKunenaImage object.
     if ($createNew) {
         // Create the new CKunenaImage object for the new truecolor image handle.
         $new = new CKunenaImage($handle);
         return $new;
     } else {
         // Swap out the current handle for the new image handle.
         $this->_handle =& $handle;
         return true;
     }
 }
Example #9
0
 public function resize($width, $height, $createNew = true, $scaleMethod = self::SCALE_INSIDE)
 {
     if (!$this->isLoaded()) {
         throw new LogicException('No valid image was loaded.');
     }
     $width = $this->sanitizeWidth($width, $height);
     $height = $this->sanitizeHeight($height, $width);
     $dimensions = $this->prepareDimensions($width, $height, $scaleMethod);
     $offset = new stdClass();
     $offset->x = $offset->y = 0;
     if ($scaleMethod == self::SCALE_FIT) {
         $offset->x = round(($width - $dimensions->width) / 2);
         $offset->y = round(($height - $dimensions->height) / 2);
         $handle = imagecreatetruecolor($width, $height);
         if (!$this->isTransparent()) {
             $transparency = imagecolorAllocateAlpha($this->handle, 0, 0, 0, 127);
             imagecolorTransparent($this->handle, $transparency);
         }
     } else {
         $handle = imagecreatetruecolor($dimensions->width, $dimensions->height);
     }
     imagealphablending($handle, false);
     imagesavealpha($handle, true);
     if ($this->isTransparent()) {
         $rgba = imageColorsForIndex($this->handle, imagecolortransparent($this->handle));
         $color = imageColorAllocateAlpha($this->handle, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
         imagecolortransparent($handle, $color);
         imagefill($handle, 0, 0, $color);
         imagecopyresized($handle, $this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     } else {
         imagecopyresampled($handle, $this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     }
     if ($createNew) {
         $new = new JImage($handle);
         return $new;
     } else {
         $this->destroy();
         $this->handle = $handle;
         return $this;
     }
 }
Example #10
0
function grayscale(&$im)
{
    $total = imagecolorstotal($im);
    for ($i = 0; $i < $total; $i++) {
        $arr = imageColorsForIndex($im, $i);
        $r = colorgray($arr);
        imageColorSet($im, $i, $r["red"], $r["green"], $r["blue"]);
    }
    return $im;
}
Example #11
0
 public function createThumbnail($width, $height, $crop, $quality, $filter, $to_path, $handle_high_resolution = false)
 {
     $creation_success = false;
     $to_path_high_res = '';
     if ($handle_high_resolution) {
         $width = $width * 2;
         $height = $height * 2;
         $to_path_high_res = str_replace(".", "@2x.", $to_path);
     }
     if ($crop) {
         $ratio = max($width / $this->image_width, $height / $this->image_height);
         $thumbnail_width = $width;
         $thumbnail_height = $height;
         $w = $width / $ratio;
         $h = $height / $ratio;
         $x = ($this->image_width - $width / $ratio) / 2;
         $y = ($this->image_height - $height / $ratio) / 2;
     } else {
         $ratio = min($width / $this->image_width, $height / $this->image_height);
         $thumbnail_width = $this->image_width * $ratio;
         $thumbnail_height = $this->image_height * $ratio;
         $w = $this->image_width;
         $h = $this->image_height;
         $x = 0;
         $y = 0;
     }
     $thumbnail = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
     if ($thumbnail == false) {
         return $creation_success;
     } else {
         if ($this->isTransparent()) {
             // only works with .gif!
             // Get the transparent color values for the current image
             $rgba = imageColorsForIndex($this->image, imagecolortransparent($this->image));
             $color = imageColorAllocate($this->image, $rgba['red'], $rgba['green'], $rgba['blue']);
             // Set the transparent color values for the new image
             imagecolortransparent($thumbnail, $color);
             imagefill($thumbnail, 0, 0, $color);
             imagecopyresized($thumbnail, $this->image, 0, 0, $x, $y, $thumbnail_width, $thumbnail_height, $w, $h);
         } else {
             imagecolortransparent($thumbnail, imagecolorallocatealpha($thumbnail, 0, 0, 0, 127));
             imagealphablending($thumbnail, false);
             imagesavealpha($thumbnail, true);
             imagecopyresampled($thumbnail, $this->image, 0, 0, $x, $y, $thumbnail_width, $thumbnail_height, $w, $h);
         }
         if (!is_null($filter)) {
             if (is_array($filter)) {
                 extract($filter);
                 if (!isset($arg2)) {
                     imagefilter($thumbnail, $type, $arg1);
                 } else {
                     if (!isset($arg3)) {
                         imagefilter($thumbnail, $type, $arg1, $arg2);
                     } else {
                         if (!isset($arg4)) {
                             imagefilter($thumbnail, $type, $arg1, $arg2, $arg3);
                         } else {
                             imagefilter($thumbnail, $type, $arg1, $arg2, $arg3, $arg4);
                         }
                     }
                 }
             } else {
                 imagefilter($thumbnail, $filter);
             }
         }
         switch ($this->image_mimetype) {
             case 'image/gif':
                 if ($handle_high_resolution) {
                     $this->thumbnail_high_res = $thumbnail;
                     $creation_high_res_success = imagegif($this->thumbnail_high_res, $to_path_high_res);
                     $this->thumbnail = imagecreatetruecolor($thumbnail_width / 2, $thumbnail_height / 2);
                     if ($this->thumbnail == false) {
                         return $creation_success;
                     }
                     // keep transparency
                     $rgba = imageColorsForIndex($this->thumbnail_high_res, imagecolortransparent($this->thumbnail_high_res));
                     $color = imageColorAllocate($this->thumbnail_high_res, $rgba['red'], $rgba['green'], $rgba['blue']);
                     imagecolortransparent($this->thumbnail, $color);
                     imagefill($this->thumbnail, 0, 0, $color);
                     if (!imagecopyresampled($this->thumbnail, $this->thumbnail_high_res, 0, 0, 0, 0, $thumbnail_width / 2, $thumbnail_height / 2, $thumbnail_width, $thumbnail_height)) {
                         $creation_low_res_success = false;
                     } else {
                         $creation_low_res_success = imagegif($this->thumbnail, $to_path);
                     }
                     if ($creation_high_res_success && $creation_low_res_success) {
                         $creation_success = true;
                     }
                 } else {
                     $this->thumbnail = $thumbnail;
                     $creation_success = imagegif($this->thumbnail, $to_path);
                 }
                 break;
             case 'image/jpeg':
                 if ($handle_high_resolution) {
                     $this->thumbnail_high_res = $thumbnail;
                     $creation_high_res_success = imagejpeg($this->thumbnail_high_res, $to_path_high_res, $quality);
                     $this->thumbnail = imagecreatetruecolor($thumbnail_width / 2, $thumbnail_height / 2);
                     if ($this->thumbnail == false) {
                         return $creation_success;
                     }
                     if (!imagecopyresampled($this->thumbnail, $this->thumbnail_high_res, 0, 0, 0, 0, $thumbnail_width / 2, $thumbnail_height / 2, $thumbnail_width, $thumbnail_height)) {
                         $creation_low_res_success = false;
                     } else {
                         $creation_low_res_success = imagejpeg($this->thumbnail, $to_path, $quality);
                     }
                     if ($creation_high_res_success && $creation_low_res_success) {
                         $creation_success = true;
                     }
                 } else {
                     $this->thumbnail = $thumbnail;
                     $creation_success = imagejpeg($this->thumbnail, $to_path, $quality);
                 }
                 break;
             case 'image/png':
                 if ($handle_high_resolution) {
                     $this->thumbnail_high_res = $thumbnail;
                     $creation_high_res_success = imagepng($this->thumbnail_high_res, $to_path_high_res, $quality);
                     $this->thumbnail = imagecreatetruecolor($thumbnail_width / 2, $thumbnail_height / 2);
                     if ($this->thumbnail == false) {
                         return $creation_success;
                     }
                     // keep transparency
                     $alpha_channel = imagecolorallocatealpha($this->thumbnail, 0, 0, 0, 127);
                     imagecolortransparent($this->thumbnail, $alpha_channel);
                     imagefill($this->thumbnail, 0, 0, $alpha_channel);
                     if (!imagecopyresampled($this->thumbnail, $this->thumbnail_high_res, 0, 0, 0, 0, $thumbnail_width / 2, $thumbnail_height / 2, $thumbnail_width, $thumbnail_height)) {
                         $creation_low_res_success = false;
                     } else {
                         $creation_low_res_success = imagepng($this->thumbnail, $to_path, $quality);
                     }
                     if ($creation_high_res_success && $creation_low_res_success) {
                         $creation_success = true;
                     }
                 } else {
                     $this->thumbnail = $thumbnail;
                     $creation_success = imagepng($this->thumbnail, $to_path, $quality);
                 }
                 break;
             default:
                 return $creation_success;
         }
     }
     if ($creation_success) {
         $this->thumbnail_path = $to_path;
         $this->thumbnail_width = $thumbnail_width;
         $this->thumbnail_height = $thumbnail_height;
         if ($handle_high_resolution) {
             $this->thumbnail_high_res_path = $to_path_high_res;
             $this->thumbnail_high_res_width = $thumbnail_width;
             $this->thumbnail_high_res_height = $thumbnail_height;
             $this->thumbnail_width = $thumbnail_width / 2;
             $this->thumbnail_height = $thumbnail_height / 2;
         }
     }
     return $creation_success;
 }
 function _555()
 {
     $b1 = imageTTFBbox($this->_112, 0, $this->_111, $this->_113);
     $b2 = $b1[4];
     $b3 = abs($b1[5]);
     $im = imageCreateTrueColor($b1[4], abs($b1[5]) + 2);
     imageFill($im, 0, 0, imageColorAllocate($im, 255, 255, 255));
     imagettftext($im, $this->_112, 0, 0, $b3, imageColorAllocate($im, 0, 0, 0), $this->_111, $this->_113);
     $this->_114 = $x = imageSX($im);
     $this->_115 = $y = imageSY($im);
     $c = 0;
     $q = 1;
     $this->_057[0] = 0;
     for ($i = 0; $i < $x; $i++) {
         for ($j = 0; $j < $y; $j++) {
             $p = imageColorsForIndex($im, imageColorAt($im, $i, $j));
             if ($p['red'] < 128 && $p['green'] < 128 && $p['blue'] < 128) {
                 $this->_057[$q] = $i;
                 $this->_057[$q + 1] = $j;
                 $q += 2;
                 $c += 2;
             }
         }
     }
     $this->_057[0] = $c;
     $this->_435($this->_116);
 }
Example #13
0
 /**
  * @param $resource
  * @param $color
  * @return bool
  */
 public function set_part_color(&$resource, $color)
 {
     $replace_color = $this->HEX2RGB($color);
     if (LITE_RECOLOR_FUNCTION) {
         imageFilter($resource, IMG_FILTER_COLORIZE, $replace_color[0] - 255, $replace_color[1] - 255, $replace_color[2] - 255);
     } else {
         $width = imageSX($resource);
         $height = imageSY($resource);
         for ($y = 0; $y < $height; $y++) {
             for ($x = 0; $x < $width; $x++) {
                 $rgb = imageColorsForIndex($resource, imageColorAt($resource, $x, $y));
                 $nr = max(round($rgb['red'] * $replace_color[0] / 255), 0);
                 $ng = max(round($rgb['green'] * $replace_color[1] / 255), 0);
                 $nb = max(round($rgb['blue'] * $replace_color[2] / 255), 0);
                 imageSetPixel($resource, $x, $y, imageColorAllocateAlpha($resource, $nr, $ng, $nb, $rgb['alpha']));
             }
         }
     }
     return true;
 }
Example #14
0
 /**
  * Get pixel colors 
  * @param resource $img
  * @param int $x
  * @param intr $y
  * @return array
  */
 private static function getPixelColor($img, $x, $y)
 {
     return imageColorsForIndex($img, imageColorAt($img, $x, $y));
 }
Example #15
0
         $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'];
 } else {
     if (count(explode('.', $_FILES['image']['name'])) > 1) {
         $file_name = explode('.', $_FILES['image']['name']);
         array_pop($file_name);
Example #16
0
 /**
  * Method to resize the current image.
  *
  * @param   mixed    $width        The width of the resized image in pixels or a percentage.
  * @param   mixed    $height       The height of the resized image in pixels or a percentage.
  * @param   boolean  $createNew    If true the current image will be cloned, resized and returned; else
  *                                 the current image will be resized and returned.
  * @param   integer  $scaleMethod  Which method to use for scaling
  *
  * @return  Image
  *
  * @since   1.0
  * @throws  \LogicException
  */
 public function resize($width, $height, $createNew = true, $scaleMethod = self::SCALE_INSIDE)
 {
     // Make sure the resource handle is valid.
     if (!$this->isLoaded()) {
         throw new \LogicException('No valid image was loaded.');
     }
     // Sanitize width.
     $width = $this->sanitizeWidth($width, $height);
     // Sanitize height.
     $height = $this->sanitizeHeight($height, $width);
     // Prepare the dimensions for the resize operation.
     $dimensions = $this->prepareDimensions($width, $height, $scaleMethod);
     // Instantiate offset.
     $offset = new \stdClass();
     $offset->x = $offset->y = 0;
     // Center image if needed and create the new truecolor image handle.
     if ($scaleMethod == self::SCALE_FIT) {
         // Get the offsets
         $offset->x = round(($width - $dimensions->width) / 2);
         $offset->y = round(($height - $dimensions->height) / 2);
         $handle = imagecreatetruecolor($width, $height);
         // Make image transparent, otherwise canvas outside initial image would default to black
         if (!$this->isTransparent()) {
             $transparency = imagecolorAllocateAlpha($this->handle, 0, 0, 0, 127);
             imagecolorTransparent($this->handle, $transparency);
         }
     } else {
         $handle = imagecreatetruecolor($dimensions->width, $dimensions->height);
     }
     // Allow transparency for the new image handle.
     imagealphablending($handle, false);
     imagesavealpha($handle, true);
     if ($this->isTransparent()) {
         // Get the transparent color values for the current image.
         $rgba = imageColorsForIndex($this->handle, imagecolortransparent($this->handle));
         $color = imageColorAllocateAlpha($this->handle, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
         // Set the transparent color values for the new image.
         imagecolortransparent($handle, $color);
         imagefill($handle, 0, 0, $color);
     }
     // Use resampling for better quality
     imagecopyresampled($handle, $this->handle, $offset->x, $offset->y, 0, 0, $dimensions->width, $dimensions->height, $this->getWidth(), $this->getHeight());
     // If we are resizing to a new image, create a new JImage object.
     if ($createNew) {
         // @codeCoverageIgnoreStart
         $new = new Image($handle);
         return $new;
         // @codeCoverageIgnoreEnd
     } else {
         // Free the memory from the current handle
         $this->destroy();
         $this->handle = $handle;
         return $this;
     }
 }
Example #17
0
 /**
  * @result mixed RGBA array for a color with index $colorIndex
  */
 function getColorRGB($colorIndex)
 {
     return imageColorsForIndex($this->handle, $colorIndex);
 }
Example #18
0
 function image_colorize4(&$img, $rgb)
 {
     imageTrueColorToPalette($img, true, 256);
     $numColors = imageColorsTotal($img);
     for ($x = 0; $x < $numColors; $x++) {
         list($r, $g, $b) = array_values(imageColorsForIndex($img, $x));
         $grayscale = ($r + $g + $b) / 3 / 0xff;
         imageColorSet($img, $x, $grayscale * $rgb[0], $grayscale * $rgb[1], $grayscale * $rgb[2]);
     }
 }
Example #19
0
 function _adjustTransparency(&$Source, &$Destination)
 {
     if ($this->_isTransparent($Source)) {
         $rgba = imageColorsForIndex($Source, imageColorTransparent($Source));
         $color = imageColorAllocate($Destination, $rgba['red'], $rgba['green'], $rgba['blue']);
         imageColorTransparent($Destination, $color);
         imageFill($Destination, 0, 0, $color);
     } else {
         if ($this->_format == 'png') {
             imageAlphaBlending($Destination, false);
             imageSaveAlpha($Destination, true);
         } elseif ($this->_format != 'gif') {
             $white = imageColorAllocate($Destination, 255, 255, 255);
             imageFill($Destination, 0, 0, $white);
         }
     }
 }
 /**
  * Copy an image on another one and converse transparency
  *
  * @param resource $destImg
  * @param resource $srcImg
  * @param integer $destX
  * @param integer $destY
  * @param integer $srcX
  * @param integer $srcY
  * @param integer $srcW
  * @param integer $srcH
  * @param integer $pct
  */
 public static function imageCopyMergeAlpha(&$destImg, &$srcImg, $destX, $destY, $srcX, $srcY, $srcW, $srcH, $pct = 0)
 {
     $destX = (int) $destX;
     $destY = (int) $destY;
     $srcX = (int) $srcX;
     $srcY = (int) $srcY;
     $srcW = (int) $srcW;
     $srcH = (int) $srcH;
     $pct = (int) $pct;
     $destW = imageSX($destImg);
     $destH = imageSY($destImg);
     for ($y = 0; $y < $srcH + $srcY; $y++) {
         for ($x = 0; $x < $srcW + $srcX; $x++) {
             if ($x + $destX >= 0 && $x + $destX < $destW && $x + $srcX >= 0 && $x + $srcX < $srcW && $y + $destY >= 0 && $y + $destY < $destH && $y + $srcY >= 0 && $y + $srcY < $srcH) {
                 $destPixel = imageColorsForIndex($destImg, imageColorat($destImg, $x + $destX, $y + $destY));
                 $srcImgColorat = imageColorat($srcImg, $x + $srcX, $y + $srcY);
                 if ($srcImgColorat > 0) {
                     $srcPixel = imageColorsForIndex($srcImg, $srcImgColorat);
                     $srcAlpha = 1 - $srcPixel['alpha'] / 127;
                     $destAlpha = 1 - $destPixel['alpha'] / 127;
                     $opacity = $srcAlpha * $pct / 100;
                     if ($destAlpha >= $opacity) {
                         $alpha = $destAlpha;
                     }
                     if ($destAlpha < $opacity) {
                         $alpha = $opacity;
                     }
                     if ($alpha > 1) {
                         $alpha = 1;
                     }
                     if ($opacity > 0) {
                         $destRed = round($destPixel['red'] * $destAlpha * (1 - $opacity));
                         $destGreen = round($destPixel['green'] * $destAlpha * (1 - $opacity));
                         $destBlue = round($destPixel['blue'] * $destAlpha * (1 - $opacity));
                         $srcRed = round($srcPixel['red'] * $opacity);
                         $srcGreen = round($srcPixel['green'] * $opacity);
                         $srcBlue = round($srcPixel['blue'] * $opacity);
                         $red = round(($destRed + $srcRed) / ($destAlpha * (1 - $opacity) + $opacity));
                         $green = round(($destGreen + $srcGreen) / ($destAlpha * (1 - $opacity) + $opacity));
                         $blue = round(($destBlue + $srcBlue) / ($destAlpha * (1 - $opacity) + $opacity));
                         if ($red > 255) {
                             $red = 255;
                         }
                         if ($green > 255) {
                             $green = 255;
                         }
                         if ($blue > 255) {
                             $blue = 255;
                         }
                         $alpha = round((1 - $alpha) * 127);
                         $color = imageColorAllocateAlpha($destImg, $red, $green, $blue, $alpha);
                         imageSetPixel($destImg, $x + $destX, $y + $destY, $color);
                     }
                 }
             }
         }
     }
 }