function TextToImage($text, $separate_line_after_chars = 40, $size = 24, $rotate = 0, $padding = 2, $transparent = true, $color = array('red' => 0, 'grn' => 0, 'blu' => 0), $bg_color = array('red' => 255, 'grn' => 255, 'blu' => 255)) { $amount_of_lines = ceil(strlen($text) / $separate_line_after_chars); $x = explode("\n", $text); $final = ''; foreach ($x as $key => $value) { $returnes = ''; do { $first_part = mb_substr($value, 0, $separate_line_after_chars, 'utf-8'); $value = "\n" . mb_substr($value, $separate_line_after_chars, null, 'utf-8'); $returnes .= $first_part; } while (mb_strlen($value, 'utf-8') > $separate_line_after_chars); $final .= $returnes . "\n"; } $text = $final; $width = $height = $offset_x = $offset_y = 0; $font = $_SERVER['DOCUMENT_ROOT'] . '/assets/css/journal.ttf'; // get the font height. $bounds = ImageTTFBBox($size, $rotate, $font, "W"); if ($rotate < 0) { $font_height = abs($bounds[7] - $bounds[1]); } elseif ($rotate > 0) { $font_height = abs($bounds[1] - $bounds[7]); } else { $font_height = abs($bounds[7] - $bounds[1]); } // determine bounding box. $bounds = ImageTTFBBox($size, $rotate, $font, $text); if ($rotate < 0) { $width = abs($bounds[4] - $bounds[0]); $height = abs($bounds[3] - $bounds[7]); $offset_y = $font_height; $offset_x = 0; } elseif ($rotate > 0) { $width = abs($bounds[2] - $bounds[6]); $height = abs($bounds[1] - $bounds[5]); $offset_y = abs($bounds[7] - $bounds[5]) + $font_height; $offset_x = abs($bounds[0] - $bounds[6]); } else { $width = abs($bounds[4] - $bounds[6]); $height = abs($bounds[7] - $bounds[1]); $offset_y = $font_height; $offset_x = 0; } $image = imagecreate($width + $padding * 2 + 1, $height + $padding * 2 + 1); $background = ImageColorAllocate($image, $bg_color['red'], $bg_color['grn'], $bg_color['blu']); $foreground = ImageColorAllocate($image, $color['red'], $color['grn'], $color['blu']); if ($transparent) { ImageColorTransparent($image, $background); } ImageInterlace($image, true); // render the image ImageTTFText($image, $size, $rotate, $offset_x + $padding, $offset_y + $padding, $foreground, $font, $text); imagealphablending($image, true); imagesavealpha($image, true); // output PNG object. imagePNG($image, 'signature.png'); imagedestroy($image); }
function draw() { $width = 0; $height = 0; $offset_x = 0; $offset_y = 0; $bounds = array(); $image = ""; // get the font height. $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W"); if ($this->rot < 0) { $font_height = abs($bounds[7] - $bounds[1]); } else { if ($this->rot > 0) { $font_height = abs($bounds[1] - $bounds[7]); } else { $font_height = abs($bounds[7] - $bounds[1]); } } // determine bounding box. $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg); if ($this->rot < 0) { $width = abs($bounds[4] - $bounds[0]); $height = abs($bounds[3] - $bounds[7]); $offset_y = $font_height; $offset_x = 0; } else { if ($this->rot > 0) { $width = abs($bounds[2] - $bounds[6]); $height = abs($bounds[1] - $bounds[5]); $offset_y = abs($bounds[7] - $bounds[5]) + $font_height; $offset_x = abs($bounds[0] - $bounds[6]); } else { $width = abs($bounds[4] - $bounds[6]); $height = abs($bounds[7] - $bounds[1]); $offset_y = $font_height; $offset_x = 0; } } $image = imagecreate($width + $this->padX * 2 + 1, $height + $this->padY * 2 + 1); $background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu); $foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu); if ($this->transparent) { ImageColorTransparent($image, $background); } ImageInterlace($image, false); // render the image ImageTTFText($image, $this->size, $this->rot, $offset_x + $this->padX, $offset_y + $this->padY, $foreground, $this->font, $this->msg); // output PNG object. imagePNG($image); }
function NewImage($width, $height, $interlace = NULL) { $this->width = $width; $this->height = $height; $this->SetFont(); if (function_exists("imagecreatetruecolor")) { $this->img = imagecreatetruecolor($this->width, $this->height); } else { $this->img = imagecreate($this->width, $this->height); } if (!$this->img) { $this->img = imagecreate($this->width, $this->height); } if (!$this->img) { return t('Unable to Initialize new GD image stream'); } ImageInterlace($this->img, $interlace); }
function OutputThumbnail() { if (!is_resource($this->gdimg_output)) { $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__); return false; } if (headers_sent()) { return $this->ErrorImage('OutputThumbnail() failed - headers already sent'); exit; } if (!empty($this->down)) { $downloadfilename = ereg_replace('[/\\:\\*\\?"<>|]', '_', $this->down); if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) { $downloadfilename = trim($downloadfilename, '.'); } if ($downloadfilename != $this->down) { $this->DebugMessage('renaming output file for "down" from "' . $this->down . '" to "' . $downloadfilename . '"', __FILE__, __LINE__); } if ($downloadfilename) { header('Content-Disposition: attachment; filename="' . $downloadfilename . '"'); } else { $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__); } } ImageInterlace($this->gdimg_output, intval($this->config_output_interlace)); $ImageOutFunction = 'image' . $this->thumbnailFormat; switch ($this->thumbnailFormat) { case 'jpeg': header('Content-type: image/' . $this->thumbnailFormat); @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality); break; case 'png': case 'gif': header('Content-type: image/' . $this->thumbnailFormat); @$ImageOutFunction($this->gdimg_output); break; } ImageDestroy($this->gdimg_output); return true; }
function generateImage($source_file, $cache_file, $resolution) { global $sharpen, $jpg_quality; $extension = strtolower(pathinfo($source_file, PATHINFO_EXTENSION)); // Check the image dimensions $dimensions = GetImageSize($source_file); $width = $dimensions[0]; $height = $dimensions[1]; // Do we need to downscale the image? if ($width <= $resolution) { // no, because the width of the source image is already less than the client width return $source_file; } // We need to resize the source image to the width of the resolution breakpoint we're working with $ratio = $height / $width; $new_width = $resolution; $new_height = ceil($new_width * $ratio); $dst = ImageCreateTrueColor($new_width, $new_height); // re-sized image switch ($extension) { case 'png': $src = @ImageCreateFromPng($source_file); // original image break; case 'gif': $src = @ImageCreateFromGif($source_file); // original image break; default: $src = @ImageCreateFromJpeg($source_file); // original image ImageInterlace($dst, true); // Enable interlancing (progressive JPG, smaller size file) break; } if ($extension == 'png') { imagealphablending($dst, false); imagesavealpha($dst, true); $transparent = imagecolorallocatealpha($dst, 255, 255, 255, 127); imagefilledrectangle($dst, 0, 0, $new_width, $new_height, $transparent); } ImageCopyResampled($dst, $src, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // do the resize in memory ImageDestroy($src); // sharpen the image? // NOTE: requires PHP compiled with the bundled version of GD (see http://php.net/manual/en/function.imageconvolution.php) if ($sharpen == TRUE && function_exists('imageconvolution')) { $intSharpness = findSharp($width, $new_width); $arrMatrix = array(array(-1, -2, -1), array(-2, $intSharpness + 12, -2), array(-1, -2, -1)); imageconvolution($dst, $arrMatrix, $intSharpness, 0); } $cache_dir = dirname($cache_file); // does the directory exist already? if (!is_dir($cache_dir)) { if (!mkdir($cache_dir, 0755, true)) { // check again if it really doesn't exist to protect against race conditions if (!is_dir($cache_dir)) { // uh-oh, failed to make that directory ImageDestroy($dst); sendErrorImage("Failed to create cache directory: {$cache_dir}"); } } } if (!is_writable($cache_dir)) { sendErrorImage("The cache directory is not writable: {$cache_dir}"); } // save the new file in the appropriate path, and send a version to the browser switch ($extension) { case 'png': $gotSaved = ImagePng($dst, $cache_file); break; case 'gif': $gotSaved = ImageGif($dst, $cache_file); break; default: $gotSaved = ImageJpeg($dst, $cache_file, $jpg_quality); break; } ImageDestroy($dst); if (!$gotSaved && !file_exists($cache_file)) { sendErrorImage("Failed to create image: {$cache_file}"); } return $cache_file; }
function OutputThumbnail() { $this->purgeTempFiles(); if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) { $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__); return false; } if (headers_sent()) { return $this->ErrorImage('OutputThumbnail() failed - headers already sent'); exit; } $downloadfilename = phpthumb_functions::SanitizeFilename(is_string($this->sia) ? $this->sia : ($this->down ? $this->down : 'phpThumb_generated_thumbnail' . '.' . $this->thumbnailFormat)); $this->DebugMessage('Content-Disposition header filename set to "' . $downloadfilename . '"', __FILE__, __LINE__); if ($downloadfilename) { header('Content-Disposition: ' . ($this->down ? 'attachment' : 'inline') . '; filename="' . $downloadfilename . '"'); } else { $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__); } if ($this->useRawIMoutput) { header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $this->IMresizedData; } else { $this->DebugMessage('ImageInterlace($this->gdimg_output, ' . intval($this->config_output_interlace) . ')', __FILE__, __LINE__); ImageInterlace($this->gdimg_output, intval($this->config_output_interlace)); switch ($this->thumbnailFormat) { case 'jpeg': header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality); break; case 'png': case 'gif': header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output); break; case 'bmp': if (!@(include_once dirname(__FILE__) . '/phpthumb.bmp.php')) { $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.bmp.php" which is required for BMP format output', __FILE__, __LINE__); return false; } $phpthumb_bmp = new phpthumb_bmp(); if (is_object($phpthumb_bmp)) { $bmp_data = $phpthumb_bmp->GD2BMPstring($this->gdimg_output); unset($phpthumb_bmp); if (!$bmp_data) { $this->DebugMessage('$phpthumb_bmp->GD2BMPstring() failed', __FILE__, __LINE__); return false; } header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $bmp_data; } else { $this->DebugMessage('new phpthumb_bmp() failed', __FILE__, __LINE__); return false; } break; case 'ico': if (!@(include_once dirname(__FILE__) . '/phpthumb.ico.php')) { $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.ico.php" which is required for ICO format output', __FILE__, __LINE__); return false; } $phpthumb_ico = new phpthumb_ico(); if (is_object($phpthumb_ico)) { $arrayOfOutputImages = array($this->gdimg_output); $ico_data = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages); unset($phpthumb_ico); if (!$ico_data) { $this->DebugMessage('$phpthumb_ico->GD2ICOstring() failed', __FILE__, __LINE__); return false; } header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $ico_data; } else { $this->DebugMessage('new phpthumb_ico() failed', __FILE__, __LINE__); return false; } break; default: $this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "' . $this->thumbnailFormat . '" is not valid', __FILE__, __LINE__); return false; break; } } return true; }
function OutputThumbnail() { if (headers_sent()) { die('OutputThumbnail() failed - headers already sent'); } $ImageOutFunction = 'image' . $this->thumbnailFormat; ImageInterlace($this->gdimg_output, 1); switch ($this->thumbnailFormat) { case 'jpeg': header('Content-type: image/' . $this->thumbnailFormat); @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality); break; case 'png': case 'gif': header('Content-type: image/' . $this->thumbnailFormat); @$ImageOutFunction($this->gdimg_output); break; } ImageDestroy($this->gdimg_output); return true; }
function OutputThumbnail() { if (!is_resource($this->gdimg_output)) { $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__); return false; } if (headers_sent()) { return $this->ErrorImage('OutputThumbnail() failed - headers already sent'); exit; } if ($this->down) { $downloadfilename = ereg_replace('[/\\:\\*\\?"<>|]', '_', $this->down); if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) { $downloadfilename = trim($downloadfilename, '.'); } if ($downloadfilename != $this->down) { $this->DebugMessage('renaming output file for "down" from "' . $this->down . '" to "' . $downloadfilename . '"', __FILE__, __LINE__); } if ($downloadfilename) { header('Content-Disposition: attachment; filename="' . $downloadfilename . '"'); } else { $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__); } } $useRawIMoutput = true; if (@$this->getimagesizeinfo[2] != 1 || $this->thumbnailFormat != 'gif') { $this->DebugMessage('RenderToFile skipping $useRawIMoutput because of $this->getimagesizeinfo[2] (' . @$this->getimagesizeinfo[2] . ') or $this->thumbnailFormat (' . $this->thumbnailFormat . ')', __FILE__, __LINE__); $useRawIMoutput = false; } else { $UnAllowedParameters = array('sx', 'sy', 'sw', 'sh', 'xto', 'ra', 'ar', 'bg', 'bc', 'fltr'); foreach ($UnAllowedParameters as $parameter) { if ($this->{$parameter}) { $useRawIMoutput = false; break; } } } if ($useRawIMoutput) { header('Content-Type: image/' . $this->thumbnailFormat); echo $this->IMresizedData; } else { ImageInterlace($this->gdimg_output, intval($this->config_output_interlace)); switch ($this->thumbnailFormat) { case 'jpeg': header('Content-Type: image/' . $this->thumbnailFormat); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality); break; case 'png': case 'gif': header('Content-Type: image/' . $this->thumbnailFormat); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output); break; default: $this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "' . $this->thumbnailFormat . '" is not valid', __FILE__, __LINE__); return false; break; } ImageDestroy($this->gdimg_output); } return true; }
function buildThumbnail() { //set cropping offset $cropX = floor(($this->image->width - $this->cropWidth) / 2); $cropY = floor(($this->image->height - $this->cropHeight) / 2); //check thumbs directory exists and create it if not if (!file_exists(dirname($this->thumbPath))) { Singapore::mkdir(dirname($this->thumbPath)); } //if file is remote then copy locally first if ($this->image->isRemote()) { $ip = @fopen($this->imagePath, "rb"); $tp = @fopen($this->thumbPath, "wb"); if ($ip && $tp) { while (fwrite($tp, fread($ip, 4095))) { } fclose($tp); fclose($ip); $this->imagePath = $this->thumbPath; } } switch ($this->config->thumbnail_software) { case "im": //use ImageMagick v5.x $cmd = '"' . $this->config->pathto_convert . '"'; if ($this->forceSize) { $cmd .= " -crop {$this->cropWidth}x{$this->cropHeight}+{$this->cropX}+{$this->cropY}"; } $cmd .= " -geometry {$this->thumbWidth}x{$this->thumbHeight}"; if ($this->image->type == 2) { $cmd .= " -quality " . $this->config->thumbnail_quality; } if ($this->config->progressive_thumbs) { $cmd .= " -interlace Plane"; } if ($this->config->remove_jpeg_profile) { $cmd .= ' +profile "*"'; } $cmd .= ' ' . escapeshellarg($this->imagePath) . ' ' . escapeshellarg($this->thumbPath); exec($cmd); break; case "im6": //use ImageMagick v6.x $cmd = '"' . $this->config->pathto_convert . '"'; $cmd .= ' ' . escapeshellarg($this->imagePath); if ($this->config->progressive_thumbs) { $cmd .= " -interlace Plane"; } if ($this->image->type == 2) { $cmd .= " -quality " . $this->config->thumbnail_quality; } if ($this->forceSize) { $cmd .= " -crop {$this->cropWidth}x{$this->cropHeight}+{$this->cropX}+{$this->cropY}"; } $cmd .= " -resize {$this->thumbWidth}x{$this->thumbHeight}"; if ($this->config->remove_jpeg_profile) { $cmd .= ' +profile "*"'; } $cmd .= ' ' . escapeshellarg($this->thumbPath); exec($cmd); break; case "gd2": case "gd1": default: //use GD by default //read in image as appropriate type switch ($this->image->type) { case 1: $image = ImageCreateFromGIF($this->imagePath); break; case 3: $image = ImageCreateFromPNG($this->imagePath); break; case 2: default: $image = ImageCreateFromJPEG($this->imagePath); break; } if ($image) { switch ($this->config->thumbnail_software) { case "gd2": //create blank truecolor image $thumb = ImageCreateTrueColor($this->thumbWidth, $this->thumbHeight); //resize image with resampling ImageCopyResampled($thumb, $image, 0, 0, $cropX, $cropY, $this->thumbWidth, $this->thumbHeight, $this->cropWidth, $this->cropHeight); break; case "gd1": default: //create blank 256 color image $thumb = ImageCreate($this->thumbWidth, $this->thumbHeight); //resize image ImageCopyResized($thumb, $image, 0, 0, $cropX, $cropY, $this->thumbWidth, $this->thumbHeight, $this->cropWidth, $this->cropHeight); break; } } /*else { $thumb = ImageCreate($this->thumbWidth, $this->thumbHeight); $bg = ImageColorAllocate($thumb, 255, 255, 255); $text = ImageColorAllocate($thumb, 255, 0, 0); ImageString($thumb, 1, 0, 0, "Cannot load source image", $text); }*/ //set image interlacing @ImageInterlace($thumb, $this->config->progressive_thumbs); //output image of appropriate type switch ($this->image->type) { case 1: //GIF images are saved as PNG //GIF images are saved as PNG case 3: ImagePNG($thumb, $this->thumbPath); break; case 2: default: ImageJPEG($thumb, $this->thumbPath, $this->config->thumbnail_quality); break; } @ImageDestroy($image); @ImageDestroy($thumb); } //set file permissions on newly created thumbnail @chmod($this->thumbPath, octdec($this->config->file_mode)); }
function complete() { ImageInterlace($this->im, 1); ImagePNG($this->im); ImageDestroy($this->im); }
function resize_image($image, $crop = false, $size = null, $addWatermark = false) { $file = $image; $image = ImageCreateFromString(file_get_contents($image)); if (is_resource($image) === true) { $x = 0; $y = 0; $width = imagesx($image); $height = imagesy($image); /* CROP (Aspect Ratio) Section----------------------------------------------------------------- */ if ($crop == false) { $crop = array($width, $height); } else { $crop = array_filter(explode(':', $crop)); // $crop = explode(':', $crop); print_r($crop); //detect if width and height ratio is "auto" if ($crop[1] == 'auto' && $crop[0] === 'auto') { $crop = array($width, $height); } //detect if height ratio is "auto" if ($crop[1] == 'auto') { $crop[1] = intval($crop[0] * $height / $width); } //end //detect if width ratio is "auto" if ($crop[0] == 'auto') { $crop[0] = intval($crop[1] * $width / $height); } //end if (empty($crop) === true) { $crop = array($width, $height); } else { if (empty($crop[0]) == true || is_numeric($crop[0]) == false) { $crop[0] = $crop[1]; } else { if (empty($crop[1]) == true || is_numeric($crop[1]) == false) { $crop[1] = $crop[0]; } } } $ratio = array(0 => $width / $height, 1 => $crop[0] / $crop[1]); if ($ratio[0] > $ratio[1]) { $width = $height * $ratio[1]; $x = (imagesx($image) - $width) / 2; } else { if ($ratio[0] < $ratio[1]) { $height = $width / $ratio[1]; $y = (imagesy($image) - $height) / 2; } } } /* Resize Section------------------------------------------------------------------------------- */ if (is_null($size) === true) { $size = array($width, $height); $indexedSize = $width . "x" . $height; } else { $indexedSize = $size; $size = array_filter(explode('x', $size)); if (empty($size) === true) { $size = array(imagesx($image), imagesy($image)); } else { if (empty($size[0]) === true || is_numeric($size[0]) === false) { $size[0] = round($size[1] * $width / $height); } else { if (empty($size[1]) === true || is_numeric($size[1]) === false) { $size[1] = round($size[0] * $height / $width); } } } } $result = ImageCreateTrueColor($size[0], $size[1]); //get file ext and remove it $filename = explode('.', $file); $ext = "." . end($filename); array_pop($filename); $filename = implode('.', $filename); //insert image resized dimension into image name $filename = explode("/", $filename); #$img_name = implode("x", $size) . '-' . end($filename); $img_name = $indexedSize . '-' . end($filename); array_pop($filename); $filepath = implode('/', $filename); $filename = $filepath . '/' . $img_name . $ext; if (is_file($filename)) { unlink($filename); } #imagejpeg($result, $filename, 100); if (is_resource($result) === true) { ImageSaveAlpha($result, true); ImageAlphaBlending($result, true); ImageFill($result, 0, 0, ImageColorAllocate($result, 255, 255, 255)); //ImageCopyResampled($result, $image, 0, -10, $x, $y, $size[0], $size[1], $width, $height); // upload axis y start at -20 ImageCopyResampled($result, $image, 0, 0, $x, $y, $size[0], $size[1], $width, $height); // upload axis y start at -20 ImageInterlace($result, true); ImageJPEG($result, $filename, 100); //give watermark only to the image with width more than 500px //if ($size[0] >= 500 && $addWatermark) //{ // $this->create_watermark($filename, $filename); //} //give watermark only to the image with width more than 500px if ($size[0] >= 435 && $addWatermark) { $this->create_watermark($filename, $filename, $addWatermark); } chmod($filename, 0644); imagedestroy($result); } else { $filename = false; } } return $filename; }
public static function edit_image($imagedata, $output_format = "jpg", $output_filename = "", $output_quality = 75, $width = "", $height = "", $keep_aspect_ratio = true, $interlace = true, $crop_x = 0, $crop_y = 0, $crop_width = -1, $crop_height = -1, $rotate_angle = 0, $fitinside = false) { $output_format = strtolower($output_format); if ($output_format === 'jpeg') { $output_format = "jpg"; } $_fromFile = strlen($imagedata) < 255 && @file_exists($imagedata); // Output format is available if (in_array($output_format, self::supported_image_types())) { // Set quality for JPG images if ($output_format === 'jpg') { // Keep quality between 1 and 99 $output_quality = max(1, min(99, is_int($output_quality) ? $output_quality : 75)); } $_gdimg = $_fromFile ? self::ImageCreateFromFileReplacement($imagedata) : self::ImageCreateFromStringReplacement($imagedata); // Now we need to ensure that we could read the file if ($_gdimg) { // Detect dimension of image $_width = ImageSX($_gdimg); $_height = ImageSY($_gdimg); if ($rotate_angle != 0 && function_exists("ImageRotate")) { $rotate_angle = floatval($rotate_angle); while ($rotate_angle < 0) { $rotate_angle += 360; } $rotate_angle = $rotate_angle % 360; if ($rotate_angle != 0) { $_gdimg = ImageRotate($_gdimg, $rotate_angle, 0); $_width = ImageSX($_gdimg); $_height = ImageSY($_gdimg); } } $_outsize = self::calculate_image_size($_width, $_height, $width, $height, $keep_aspect_ratio, true, $fitinside); // Decide, which functions to use (depends on version of GD library) $_image_create_function = self::gd_version() >= 2.0 ? "imagecreatetruecolor" : "imagecreate"; $_image_resize_function = function_exists('imagecopyresampled') ? "imagecopyresampled" : "imagecopyresized"; $_outsize["width"] = max(1, $_outsize["width"]); $_outsize["height"] = max(1, $_outsize["height"]); // Now create the image $_output_gdimg = $_image_create_function($_outsize["width"], $_outsize["height"]); // this image is always black /* $GDInfo = self::gd_info(); // DEBIAN EDGE FIX => crashes at imagefill, so use old Method if($GDInfo["GD Version"] === '2.0 or higher' && !function_exists("imagerotate")){ // set black to transparent! if($output_format === 'gif' || $output_format === 'png'){ // transparency with gifs imagecolortransparent($_output_gdimg, imagecolorallocate($_output_gdimg, 0, 0, 0)); // set this color to transparent - done } } else { */ // preserve transparency of png and gif images: switch ($output_format) { case "gif": $colorTransparent = imagecolortransparent($_gdimg); imagepalettecopy($_gdimg, $_output_gdimg); imagefill($_output_gdimg, 0, 0, $colorTransparent); imagecolortransparent($_output_gdimg, $colorTransparent); imagetruecolortopalette($_output_gdimg, true, 256); break; case "png": imagealphablending($_output_gdimg, false); //$transparent = imagecolorallocatealpha($_output_gdimg, 0, 0, 0, 127); $transparent = imagecolorallocatealpha($_output_gdimg, 255, 255, 255, 127); imagefill($_output_gdimg, 0, 0, $transparent); imagesavealpha($_output_gdimg, true); break; default: } //} // Resize image //if($_outsize["width"] == "1") if ($fitinside && $keep_aspect_ratio && $width && $height) { $wratio = $width / $_width; $hratio = $height / $_height; $ratio = max($width / $_width, $height / $_height); $h = $height / $ratio; $w = $width / $ratio; if ($wratio < $hratio) { $x = ($_width - $width / $ratio) / 2; $y = 0; } else { $x = 0; $y = ($_height - $height / $ratio) / 2; } // Set thumbnail focus point -ah2015 if (true) { echo '<script>console.log("TX:"+' . $x . ', "TY:"+' . $y . ', "OWidth:"+' . $_width . ', "TWidth"+' . $width . ', "OHeight:"+' . $_height . ', "THeight"+' . $height . ');</script>'; $x_focus = $crop_x; // von -1.0 bis 1.0 $y_focus = $crop_y; // von -1.0 bis 1.0 $x = $x + $x * $x_focus; $y = $y + $y * $y_focus; } $_image_resize_function($_output_gdimg, $_gdimg, 0, 0, $x, $y, $width, $height, $w, $h); } else { $_image_resize_function($_output_gdimg, $_gdimg, 0, 0, 0, 0, $_outsize["width"], $_outsize["height"], $_width, $_height); } // PHP 4.4.1 GDLIB-Bug/Safemode - Workarround if ($output_filename != "" && file_exists($output_filename)) { touch($output_filename); } ImageInterlace($_output_gdimg, $interlace ? 1 : 0); switch ($output_format) { case 'jpg': // Output to a filename or directly if ($output_filename != "") { $_gdimg = imagejpeg($_output_gdimg, $output_filename, $output_quality); if ($_gdimg) { $_gdimg = basename($output_filename); } } elseif ($_tempfilename = tempnam(TEMP_PATH, "")) { imagejpeg($_output_gdimg, $_tempfilename, $output_quality); $_gdimg = we_base_file::load($_tempfilename); // As we read the temporary file we no longer need it //unlink($_tempfilename); } break; case 'png': case 'gif': // Set output function $_image_out_function = 'image' . $output_format; // Output to a filename or directly if ($output_filename) { $_gdimg = $_image_out_function($_output_gdimg, $output_filename); if ($_gdimg) { $_gdimg = basename($output_filename); } } elseif ($_tempfilename = tempnam(TEMP_PATH, "")) { $_image_out_function($_output_gdimg, $_tempfilename); $_gdimg = we_base_file::load($_tempfilename); // As we read the temporary file we no longer need it unlink($_tempfilename); } break; } ImageDestroy($_output_gdimg); } return isset($_gdimg) ? array($_gdimg, $_outsize["width"], $_outsize["height"]) : array(false, -1, -1); } return array(false, -1, -1); }
/** * SICWebImage::constrain() - a GD library-based crop and resize utility * function * * Props to Alix Axel and monowerker at <http://stackoverflow.com/questions/999250/php-gd-cropping-and-resizing-images> * for some nice packaging of the code to do this with only the GD library * functions. */ function constrain($crop = null, $size = null) { $ret = NULL; if ($this->is_image() and (!is_null($crop) or !is_null($size))) { if (self::has_gd()) { $image = ImageCreateFromString($this->data()); $data = NULL; $mimetype = NULL; if (is_resource($image) === true) { $x = 0; $y = 0; $width = imagesx($image); $height = imagesy($image); /* CROP (Aspect Ratio) Section */ if (is_null($crop) === true) { $crop = array($width, $height); } else { $crop = array_filter(explode(':', $crop)); if (empty($crop) === true) { $crop = array($width, $height); } else { if (empty($crop[0]) === true || is_numeric($crop[0]) === false) { $crop[0] = $crop[1]; } elseif (empty($crop[1]) === true || is_numeric($crop[1]) === false) { $crop[1] = $crop[0]; } } $ratio = array(0 => $width / $height, 1 => $crop[0] / $crop[1]); if ($ratio[0] > $ratio[1]) { $width = $height * $ratio[1]; $x = (imagesx($image) - $width) / 2; } elseif ($ratio[0] < $ratio[1]) { $height = $width / $ratio[1]; $y = (imagesy($image) - $height) / 2; } } /* Resize Section */ if (is_null($size) === true) { $size = array($width, $height); } else { $size = array_filter(explode('x', $size)); if (empty($size) === true) { $size = array(imagesx($image), imagesy($image)); } else { if (empty($size[0]) === true || is_numeric($size[0]) === false) { $size[0] = round($size[1] * $width / $height); } elseif (empty($size[1]) === true || is_numeric($size[1]) === false) { $size[1] = round($size[0] * $height / $width); } } } $result = ImageCreateTrueColor($size[0], $size[1]); if (is_resource($result) === true) { ImageSaveAlpha($result, true); ImageAlphaBlending($result, true); ImageFill($result, 0, 0, ImageColorAllocate($result, 255, 255, 255)); ImageCopyResampled($result, $image, 0, 0, $x, $y, $size[0], $size[1], $width, $height); ImageInterlace($result, true); ob_start(); // *sigh* ImageJPEG($result, null, 90); $mimetype = 'image/jpeg'; $data = ob_get_clean(); // *sigh* } } // (is_resource($image) === true) $ret = array($data, $mimetype); } // function_exists('ImageCreateFromString') if (!is_null($ret) and !is_null($ret[0])) { $this->set_image($ret[0], $ret[1]); } } return $ret; }
protected static function _createTTFImage($txt) { if (!self::getInstance()) { return NULL; } /* else */ $bounds = ImageTTFBBox(self::$_font["size"], 0, self::$_font["family"], "W"); $fontHeight = abs($bounds[7] - $bounds[1]); $bounds = ImageTTFBBox(self::$_font["size"], 0, self::$_font["family"], $txt); $width = abs($bounds[4] - $bounds[6]); $height = abs($bounds[7] - $bounds[1]); $offsetY = $fontHeight; $offsetX = 0; $image = imagecreate($width + self::$_padding * 2 + 1, $height + self::$_padding * 2 + 1); $background = ImageColorAllocate($image, self::$_backgroundColor["color"]["red"], self::$_backgroundColor["color"]["green"], self::$_backgroundColor["color"]["blue"]); $foreground = ImageColorAllocate($image, self::$_font["color"]["red"], self::$_font["color"]["green"], self::$_font["color"]["blue"]); if (self::$_transparent) { ImageColorTransparent($image, $background); } ImageInterlace($image, false); // render the image ImageTTFText($image, self::$_font["size"], 0, $offsetX + self::$_padding, $offsetY + self::$_padding, $foreground, self::$_font["family"], $txt); // print_r( self::$_font ); return $image; }
} elseif ($page_ip < 1000) { $page_ip_txt = "00000{$page_ip}"; } elseif ($page_ip < 10000) { $page_ip_txt = "0000{$page_ip}"; } elseif ($page_ip < 100000) { $page_ip_txt = "000{$page_ip}"; } elseif ($page_ip < 1000000) { $page_ip_txt = "00{$page_ip}"; } elseif ($page_ip < 10000000) { $page_ip_txt = "0{$page_ip}"; } elseif ($page_ip < 100000000) { $page_ip_txt = "{$page_ip}"; } else { $page_ip_txt = " Error!"; } // show img ------------------------- header('Content-type: image/' . $lvc_images_format); $imgfile = 'images/counter.' . $lvc_images_format; $fct_imagecreatefrom = 'imagecreatefrom' . $lvc_images_format; $img = $fct_imagecreatefrom($imgfile); $black = imagecolorallocate($img, 0, 0, 0); $white = imagecolorallocate($img, 255, 255, 255); $yellow = imagecolorallocate($img, 255, 255, 0); ImageString($img, 3, 26, 5, "{$page_ip_txt}", $black); ImageString($img, 3, 25, 4, "{$page_ip_txt}", $white); ImageString($img, 1, 5, 22, $count_date, $black); ImageString($img, 1, 4, 21, $count_date, $yellow); ImageInterlace($img, 1); $fct_image = 'image' . $lvc_images_format; $fct_image($img); ImageDestroy($img);
/** * @param array $options * * @return bool|null */ public function makeThumbnail($options = array()) { $phpThumb = new modPhpThumb($this->xpdo); $phpThumb->initialize(); $tf = tempnam(MODX_BASE_PATH, 'ms_'); file_put_contents($tf, $this->file['content']); $phpThumb->setSourceFilename($tf); foreach ($options as $k => $v) { $phpThumb->setParameter($k, $v); } if ($phpThumb->GenerateThumbnail()) { ImageInterlace($phpThumb->gdimg_output, true); if ($phpThumb->RenderOutput()) { @unlink($phpThumb->sourceFilename); @unlink($tf); return $phpThumb->outputImageData; } } else { $this->xpdo->log(modX::LOG_LEVEL_ERROR, 'Could not generate thumbnail for "' . $this->get('url') . '". ' . print_r($phpThumb->debugmessages, 1)); } return false; }
$radius = $xSize < $ySize ? floor($xSize / 2) : floor($ySize / 2); //픽셀 } //1씩 더 크게 만든다 $im = ImageCreate($xSize + 1, $ySize + 1); $white = ImageColorAllocate($im, 255, 255, 255); $black = ImageColorAllocate($im, 0, 0, 0); //make array. $arr = array(); for ($i = 0; $i < 6; $i++) { $c1 = rand(0, 255); $c2 = rand(0, 255); $c3 = rand(0, 255); $arr[$i][color_identifier] = ImageColorAllocate($im, $c1, $c2, $c3); $arr[$i][money] = rand(1, 100); $arr[$i][name] = $i . ".item."; } /* $count_arr = count($arr); for($i=0; $i<$count_arr; $i++){ $hexcolor = hex2dec_all($arr[$i][color]); $arr[$i][color_identifier] = ImageColorAllocate($im, $hexcolor[0],$hexcolor[1],$hexcolor[2]); } */ //원그래프 그리기. MakeCircularGraph($im, $radius, $radius, $radius, $arr, "money", $black, "name", 0); //MakeCircularGraph2($im, $radius, $radius, $radius, $arr, "money", $black, "name"); //이미지가 점점 선명해 지는 방식 ImageInterlace($im, 1); ImagePng($im); ImageDestroy($im);
function OutputThumbnail() { if (headers_sent()) { die('OutputThumbnail() failed - headers already sent'); } $downloadfilename = ereg_replace('[/\\:\\*\\?"<>|]', '_', $this->down); if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) { $downloadfilename = trim($downloadfilename, '.'); } if (!empty($downloadfilename)) { header('Content-Disposition: attachment; filename="' . $downloadfilename . '"'); } ImageInterlace($this->gdimg_output, intval($this->config_output_interlace)); $ImageOutFunction = 'image' . $this->thumbnailFormat; switch ($this->thumbnailFormat) { case 'jpeg': header('Content-type: image/' . $this->thumbnailFormat); @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality); break; case 'png': case 'gif': header('Content-type: image/' . $this->thumbnailFormat); @$ImageOutFunction($this->gdimg_output); break; } ImageDestroy($this->gdimg_output); return true; }
function Image($image, $crop = null, $size = null, $user) { $image = ImageCreateFromString(file_get_contents($image)); if (is_resource($image) === true) { $x = 0; $y = 0; $width = imagesx($image); $height = imagesy($image); /* CROP (Aspect Ratio) Section */ if (is_null($crop) === true) { $crop = array($width, $height); } else { $crop = array_filter(explode(':', $crop)); if (empty($crop) === true) { $crop = array($width, $height); } else { if (empty($crop[0]) === true || is_numeric($crop[0]) === false) { $crop[0] = $crop[1]; } else { if (empty($crop[1]) === true || is_numeric($crop[1]) === false) { $crop[1] = $crop[0]; } } } $ratio = array(0 => $width / $height, 1 => $crop[0] / $crop[1]); if ($ratio[0] > $ratio[1]) { $width = $height * $ratio[1]; $x = (imagesx($image) - $width) / 2; } else { if ($ratio[0] < $ratio[1]) { $height = $width / $ratio[1]; $y = (imagesy($image) - $height) / 2; } } } /* Resize Section */ if (is_null($size) === true) { $size = array($width, $height); } else { $size = array_filter(explode('x', $size)); if (empty($size) === true) { $size = array(imagesx($image), imagesy($image)); } else { if (empty($size[0]) === true || is_numeric($size[0]) === false) { $size[0] = round($size[1] * $width / $height); } else { if (empty($size[1]) === true || is_numeric($size[1]) === false) { $size[1] = round($size[0] * $height / $width); } } } } $result = ImageCreateTrueColor($size[0], $size[1]); if (is_resource($result) === true) { ImageSaveAlpha($result, true); ImageAlphaBlending($result, true); ImageFill($result, 0, 0, ImageColorAllocate($result, 255, 255, 255)); ImageCopyResampled($result, $image, 0, 0, $x, $y, $size[0], $size[1], $width, $height); ImageInterlace($result, true); $file1 = $result; $file2 = 'sim33.png'; // Second image (the overlay) $overlay = imagecreatefrompng($file2); // We need to know the width and height of the overlay list($widthx, $heightx, $type, $attr) = getimagesize($file2); // Apply the overlay imagecopy($file1, $overlay, 0, 0, 0, 0, $widthx, $heightx); imagedestroy($overlay); // Output the results imagejpeg($file1, 'pics/avatar-' . $user . '.jpg', 90); echo '<img src="pics/avatar-' . $user . '.jpg" alt="">'; imagedestroy($file1); //ImageJPEG($result, null, 90); } } return false; }
function GetMarkedImage($type = HANDLE, $param1 = "", $param2 = "", $param3 = "") { if ($this->marked_image != -1) { $type = StrToUpper($type); switch ($type) { case HANDLE: return $this->marked_image; case _IMG_PNG: if ($param1 != "") { ImagePNG($this->marked_image, $param1); } else { ImagePNG($this->marked_image); } return true; case _IMG_GIF: if ($param1 != "") { ImageGIF($this->marked_image, $param1); } else { ImageGIF($this->marked_image); } return true; case _IMG_JPEG: if (StrToUpper($param3) == "YES") { ImageInterlace($this->marked_image, 1); } else { ImageInterlace($this->marked_image, 0); } if ($param2 == "") { $param2 = 75; } ImageJPEG($this->marked_image, $param1, $param2); return true; default: $this->dieError("Unknown output type in getMarkedImage method!"); } } return false; }
public function createThumbNail($pointer, $filename) { if ($this->check[$pointer] == 'checked') { //Verifica se será feito o redimensionamento //Se for permitido tanto expandir como diminuir a imagem if ($this->re_go[$pointer] == self::$_IMG_GO_BOTH) { $resize = true; //Se for permitido somente diminuir a imagem } else { if ($this->re_go[$pointer] == self::$_IMG_GO_SMALL) { //Faz a verificação tanto para altura quanto para largura if ($this->re_resize[$pointer] == self::$_IMG_RESIZE_PROPORTIONAL) { $resize = $this->width[$pointer] > $this->re_width[$pointer] || $this->height[$pointer] > $this->re_height[$pointer] ? true : false; //Faz a verificação somente para a altura } else { if ($this->re_resize[$pointer] == self::$_IMG_RESIZE_PROPORTIONAL_HEIGHT) { $resize = $this->height[$pointer] > $this->re_height[$pointer] ? true : false; //Faz a verifcação somente para a largura } else { $resize = $this->width[$pointer] > $this->re_width[$pointer] ? true : false; } } //Se for permitida somente expandir a imagem } else { //Faz a verificação tanto para altura quanto para largura if ($this->re_resize[$pointer] == self::$_IMG_RESIZE_PROPORTIONAL) { $resize = $this->width[$pointer] < $this->re_width[$pointer] || $this->height[$pointer] < $this->re_height[$pointer] ? true : false; //Faz a verificação somente para a altura } else { if ($this->re_resize[$pointer] == self::$_IMG_RESIZE_PROPORTIONAL_HEIGHT) { $resize = $this->height[$pointer] < $this->re_height[$pointer] ? true : false; //Faz a verifcação somente para a largura } else { $resize = $this->width[$pointer] < $this->re_width[$pointer] ? true : false; } } } } //Caso seja necessário redimensionar if ($resize) { $array['resource'] = $this->typeCreateImage($pointer); $this->resource[$pointer] = $array['resource']; $properties = $this->properties($pointer); $array['resized'] = ImageCreateTrueColor($properties["resized_width"], $properties["resized_height"]); $array['copy'] = ImageCopyResampled($array['resized'], $array['resource'], 0, 0, 0, 0, $properties["resized_width"], $properties["resized_height"], $properties["width"], $properties["height"]); $array['interlace'] = ImageInterlace($array['resized'], 1); $array['save'] = $this->typeCloseImage($pointer, $array['resized'], $filename); $array['destroy'] = ImageDestroy($array['resource']); ImageDestroy($array['resized']); if (array_search(false, $array, 1) === false) { $this->re_size[$pointer] = filesize($filename); return true; } else { return false; } //Caso não seja necessário redimensionar, então faz só uma cópia } else { $this->re_size[$pointer] = $this->size[$pointer]; return $this->image[$pointer] == $filename ? true : copy($this->image[$pointer], $filename); } //Caso a imagem não exista } else { return false; } }
function make_thumb($image_path, $thumb_path, $max_width = 1200, $max_height = 1200, $force_size, $software = "gd2", $convert_path = null) { $convert_path = '/opt/local/bin/convert'; $thumbQuality = 95; list($image_width, $image_height, $image_type) = GetImageSize($image_path); //if aspect ratio is to be constrained set crop size if ($force_size) { $newAspect = $max_width / $max_height; $oldAspect = $image_width / $image_height; if ($newAspect > $oldAspect) { $cropWidth = $image_width; $cropHeight = round($oldAspect / $newAspect * $image_height); } else { $cropWidth = round($newAspect / $oldAspect * $image_width); $cropHeight = $image_height; } //else crop size is image size } else { $cropWidth = $image_width; $cropHeight = $image_height; } //set cropping offset $cropX = floor(($image_width - $cropWidth) / 2); $cropY = floor(($image_height - $cropHeight) / 2); //compute width and height of thumbnail to create if ($cropWidth >= $max_width && ($cropHeight < $max_height || $cropHeight > $max_height && round($cropWidth / $cropHeight * $max_height) > $max_width)) { $thumbWidth = $max_width; $thumbHeight = round($cropHeight / $cropWidth * $max_width); } elseif ($cropHeight >= $max_height) { $thumbWidth = round($cropWidth / $cropHeight * $max_height); $thumbHeight = $max_height; } else { //image is smaller than required dimensions so output it and exit readfile($image_path); exit; } switch ($software) { case "im": //use ImageMagick // hack for square thumbs; if ($thumbWidth == $thumbHeight or $force_size) { $thumbsize = $thumbWidth; if ($image_height > $image_width) { $cropY = -($thumbsize / 2); $cropX = 0; $thumbcommand = "{$thumbsize}x"; } else { $cropY = -($thumbsize / 2); $cropX = 0; $thumbcommand = "x{$thumbsize}"; } } else { $thumbcommand = $thumbWidth . 'x' . $thumbHeight; } $cmd = '"' . $convert_path . '"'; if ($force_size) { $cmd .= " -gravity center -crop {$thumbWidth}x{$thumbHeight}!+0+0"; } $cmd .= " -resize {$thumbcommand}"; if ($image_type == 2) { $cmd .= " -quality {$thumbQuality}"; } $cmd .= " -interlace Plane"; $cmd .= ' +profile "*"'; $cmd .= ' ' . escapeshellarg($image_path) . ' ' . escapeshellarg($thumb_path); exec($cmd); readfile($thumb_path); exit; break; case "gd2": default: //use GD by default //read in image as appropriate type switch ($image_type) { case 1: $image = ImageCreateFromGIF($image_path); break; case 3: $image = ImageCreateFromPNG($image_path); break; case 2: default: $image = ImageCreateFromJPEG($image_path); break; } //create blank truecolor image $thumb = ImageCreateTrueColor($thumbWidth, $thumbHeight); //resize image with resampling ImageCopyResampled($thumb, $image, 0, 0, $cropX, $cropY, $thumbWidth, $thumbHeight, $cropWidth, $cropHeight); //set image interlacing ImageInterlace($thumb, $this->config->progressive_thumbs); //output image of appropriate type switch ($image_type) { case 1: //GIF images are output as PNG //GIF images are output as PNG case 3: ImagePNG($thumb, $thumb_path); break; case 2: default: ImageJPEG($thumb, $thumb_path, $thumbQuality); break; } ImageDestroy($image); ImageDestroy($thumb); readfile($thumb_path); } }
function draw() { putenv('GDFONTPATH=' . APPLICATION_PATH . '/../library/fonts'); $width = 0; $height = 0; $offset_x = 0; $offset_y = 0; $bounds = array(); $image = ""; $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W"); if ($this->rot < 0) { $font_height = abs($bounds[7] - $bounds[1]); } else { if ($this->rot > 0) { $font_height = abs($bounds[1] - $bounds[7]); } else { $font_height = abs($bounds[7] - $bounds[1]); } } $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg); if ($this->rot < 0) { $width = abs($bounds[4] - $bounds[0]); $height = abs($bounds[3] - $bounds[7]); $offset_y = $font_height; $offset_x = 0; } else { if ($this->rot > 0) { $width = abs($bounds[2] - $bounds[6]); $height = abs($bounds[1] - $bounds[5]); $offset_y = abs($bounds[7] - $bounds[5]) + $font_height; $offset_x = abs($bounds[0] - $bounds[6]); } else { $width = abs($bounds[4] - $bounds[6]); $height = abs($bounds[7] - $bounds[1]); $offset_y = $font_height; $offset_x = 0; } } $image = imagecreate($width + $this->pad * 2 + 1, $height + $this->pad * 2 + 1); $background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu); $foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu); if ($this->transparent) { ImageColorTransparent($image, $background); } ImageInterlace($image, false); ImageTTFText($image, $this->size, $this->rot, $offset_x + $this->pad, $offset_y + $this->pad, $foreground, $this->font, $this->msg); imagePNG($image); }
/** * Output the Thumbnail * * @return \Zend\Http\Response * @throws Exception */ public function OutputThumbnail() { $this->purgeTempFiles(); if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) { throw new \Exception('OutputThumbnail() failed because !is_resource($this->gdimg_output)'); } if (headers_sent()) { throw new \Exeception('OutputThumbnail() failed - headers already sent'); } $downloadfilename = phpthumb_functions::SanitizeFilename(is_string($this->sia) ? $this->sia : ($this->down ? $this->down : 'phpThumb_generated_thumbnail' . '.' . $this->thumbnailFormat)); $response = new Response(); if ($downloadfilename) { $response->getHeaders()->addHeaderLine('Content-Disposition', ($this->down ? 'attachment' : 'inline') . '; filename="' . $downloadfilename . '"'); } if ($this->useRawIMoutput) { $response->getHeaders()->addHeaderLine('Content-Type', phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); $response->setContent($this->IMresizedData); } else { $response->getHeaders()->addHeaderLine('Content-Type', phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); ImageInterlace($this->gdimg_output, intval($this->config_output_interlace)); switch ($this->thumbnailFormat) { case 'jpeg': $ImageOutFunction = 'image' . $this->thumbnailFormat; ob_start(); @$ImageOutFunction($this->gdimg_output, null, $this->thumbnailQuality); $content = ob_get_clean(); $response->setContent($content); break; case 'png': case 'gif': $ImageOutFunction = 'image' . $this->thumbnailFormat; ob_start(); @$ImageOutFunction($this->gdimg_output); $content = ob_get_clean(); $response->setContent($content); break; case 'bmp': if (!@(include_once dirname(__FILE__) . '/phpthumb.bmp.php')) { throw new \Exception('Error including "' . dirname(__FILE__) . '/phpthumb.bmp.php" which is required for BMP format output'); } $phpthumb_bmp = new phpthumb_bmp(); if (is_object($phpthumb_bmp)) { $bmp_data = $phpthumb_bmp->GD2BMPstring($this->gdimg_output); unset($phpthumb_bmp); if (!$bmp_data) { throw new \Exception('$phpthumb_bmp->GD2BMPstring() failed'); } $response->setContent($bmp_data); } else { throw new \Exception('new phpthumb_bmp() failed'); } break; case 'ico': if (!@(include_once dirname(__FILE__) . '/phpthumb.ico.php')) { throw new \Exception('Error including "' . dirname(__FILE__) . '/phpthumb.ico.php" which is required for ICO format output'); } $phpthumb_ico = new phpthumb_ico(); if (is_object($phpthumb_ico)) { $arrayOfOutputImages = array($this->gdimg_output); $ico_data = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages); unset($phpthumb_ico); if (!$ico_data) { throw new \Exception('$phpthumb_ico->GD2ICOstring() failed'); } $response->setContent($ico_data); } else { throw new \Exception('new phpthumb_ico() failed'); } break; default: throw new \Exception('OutputThumbnail failed because $this->thumbnailFormat "' . $this->thumbnailFormat . '" is not valid'); } } return $response; }
function make_thumb($gallery, $image, $image_path, $thumb_path, $max_width, $max_height, $force_size, $movie = null, $movie_path = null) { $this->config = new configuration(); if ($movie) { include_once 'includes/getid3/getid3.php'; $getID3 = new getID3(); $fileinfo = $getID3->analyze($image_path); getid3_lib::CopyTagsToComments($fileinfo); $image_width = $fileinfo['video']['resolution_x']; $image_height = $fileinfo['video']['resolution_y']; } else { $thumbQuality = $this->config->thumbnail_quality; list($image_width, $image_height, $image_type) = GetImageSize($image_path); } //if aspect ratio is to be constrained set crop size if ($force_size) { $newAspect = $max_width / $max_height; $oldAspect = $image_width / $image_height; if ($newAspect > $oldAspect) { $cropWidth = $image_width; $cropHeight = round($oldAspect / $newAspect * $image_height); } else { $cropWidth = round($newAspect / $oldAspect * $image_width); $cropHeight = $image_height; } //else crop size is image size } else { $cropWidth = $image_width; $cropHeight = $image_height; } //set cropping offset $cropX = floor(($image_width - $cropWidth) / 2); $cropY = floor(($image_height - $cropHeight) / 2); //compute width and height of thumbnail to create if ($cropWidth >= $max_width && ($cropHeight < $max_height || $cropHeight > $max_height && round($cropWidth / $cropHeight * $max_height) > $max_width)) { $thumbWidth = $max_width; $thumbHeight = round($cropHeight / $cropWidth * $max_width); } elseif ($cropHeight >= $max_height) { $thumbWidth = round($cropWidth / $cropHeight * $max_height); $thumbHeight = $max_height; } else { //image is smaller than required dimensions so output it and exit readfile($image_path); exit; } if ($movie) { $thumbHeight = floor($thumbHeight / 2) * 2; $thumbWidth = floor($thumbWidth / 2) * 2; if ($_GET['movie']) { exec($this->config->pathto_ffmpeg . ' -i ' . escapeshellarg($image_path) . ' -f flv ' . escapeshellarg($movie_path)); exec('/bin/cat ' . escapeshellarg($movie_path) . ' | ' . $this->config->pathto_flvtool . ' -U stdin ' . escapeshellarg($movie_path)); readfile($movie_path); exit; } exec($this->config->pathto_ffmpeg . ' -i ' . escapeshellarg($image_path) . ' -s ' . $thumbWidth . 'x' . $thumbHeight . ' -f mjpeg -t 1 -ss 3 ' . escapeshellarg($thumb_path)); readfile($thumb_path); exit; } switch ($this->config->thumbnail_software) { case "im": //use ImageMagick // hack for square thumbs; if ($thumbWidth == $thumbHeight or $force_size) { $thumbsize = $thumbWidth; if ($image_height > $image_width) { $cropY = -($thumbsize / 2); $cropX = 0; $thumbcommand = "{$thumbsize}x"; } else { $cropY = -($thumbsize / 2); $cropX = 0; $thumbcommand = "x{$thumbsize}"; } } else { $thumbcommand = $thumbWidth . 'x' . $thumbHeight; } $cmd = '"' . $this->config->pathto_convert . '"'; if ($force_size) { $cmd .= " -gravity center -crop {$thumbWidth}x{$thumbHeight}!+0+0"; } $cmd .= " -resize {$thumbcommand}"; if ($image_type == 2) { $cmd .= " -quality {$thumbQuality}"; } if ($this->config->progressive_thumbs) { $cmd .= " -interlace Plane"; } if ($this->config->remove_jpeg_profile) { $cmd .= ' +profile "*"'; } $cmd .= ' ' . escapeshellarg($image_path) . ' ' . escapeshellarg($thumb_path); exec($cmd); readfile($thumb_path); exit; break; case "gd2": default: //use GD by default //read in image as appropriate type switch ($image_type) { case 1: $image = ImageCreateFromGIF($image_path); break; case 3: $image = ImageCreateFromPNG($image_path); break; case 2: default: $image = ImageCreateFromJPEG($image_path); break; } //create blank truecolor image $thumb = ImageCreateTrueColor($thumbWidth, $thumbHeight); //resize image with resampling ImageCopyResampled($thumb, $image, 0, 0, $cropX, $cropY, $thumbWidth, $thumbHeight, $cropWidth, $cropHeight); //set image interlacing ImageInterlace($thumb, $this->config->progressive_thumbs); //output image of appropriate type switch ($image_type) { case 1: //GIF images are output as PNG //GIF images are output as PNG case 3: ImagePNG($thumb); ImagePNG($thumb, $thumb_path); break; case 2: default: ImageJPEG($thumb, "", $thumbQuality); ImageJPEG($thumb, $thumb_path, $thumbQuality); break; } ImageDestroy($image); ImageDestroy($thumb); } }
/** * Generates a resized version of an image and saves it in the image cache folder. * * @param string $source_file The original image to be resized. * @param string $cache_file The target file where the resized version will be cached. * @param int $resolution The resolution breakpoint at which the given image is to be resized. * @param int $jpg_quality The JPEG quality that will be used for resizing the images. * @param bool $sharpen Whether to sharpen the resized images or not. * * @return array Associative array( bool: success, string: message) with the result of the image cache generation. */ function adaptive_images_script_generate_image($source_file, $cache_file, $resolution, $jpg_quality, $sharpen) { // Get original image dimensions. $dimensions = @GetImageSize($source_file); $width = $dimensions[0]; $height = $dimensions[1]; // Calculate resized image dimensions. $ratio = $height / $width; $new_width = $resolution; $new_height = ceil($new_width * $ratio); // Start creating the resized image with a blank true color canvas. $destination = @ImageCreateTrueColor($new_width, $new_height); $extension = adaptive_images_script_get_file_extension($source_file); switch ($extension) { case 'png': $source = @ImageCreateFromPng($source_file); break; case 'gif': $source = @ImageCreateFromGif($source_file); break; default: $source = @ImageCreateFromJpeg($source_file); break; } // PNG images generation. if ($extension == 'png') { // Create a transparent color and fill the blank canvas with it. $rbga_color = @ImageColorAllocateAlpha($destination, 0, 0, 0, 127); @ImageColorTransparent($destination, $rbga_color); @ImageFill($destination, 0, 0, $rbga_color); // Copy source image to destination image with interpolation. @ImageCopyResampled($destination, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Convert true colour image to pallette image to achieve PNG-8 compression. $dither = TRUE; @ImageTrueColorToPalette($destination, $dither, 255); // Save alpha (transparency) of destination image. $save_alpha = TRUE; @ImageSaveAlpha($destination, $save_alpha); // Disable blending of destination image to allow for alpha (transparency) above. $enable_alpha_blending = FALSE; @ImageAlphaBlending($destination, $enable_alpha_blending); } // GIF images generation. if ($extension == 'gif') { // Create a transparent color and fill the blank canvas with it. $rbga_color = @ImageColorAllocateAlpha($destination, 0, 0, 0, 127); @ImageColorTransparent($destination, $rbga_color); @ImageFill($destination, 0, 0, $rbga_color); // Copy source image to destination image with interpolation. @ImageCopyResampled($destination, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Convert true colour image to pallette image to achieve PNG8 compression. $dither = TRUE; @ImageTrueColorToPalette($destination, $dither, 255); // Enable alpha blending of destination image. $enable_alpha_blending = TRUE; @ImageAlphaBlending($destination, $enable_alpha_blending); } // JPEG images generation. if ($extension == 'jpg' || $extension == 'jpeg') { // Enable JPEG interlacing. ImageInterlace($destination, TRUE); // Interpolates source image to destination image to make it more clear for JPGs. @ImageCopyResampled($destination, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); } // Cleanup source image from memory. @ImageDestroy($source); // Do sharpening if requested. if ($sharpen && function_exists('imageconvolution')) { $sharpness_factor = adaptive_images_script_sharpness_factor($width, $new_width); $sharpness_transformation_matrix = array(array(-1, -2, -1), array(-2, $sharpness_factor + 12, -2), array(-1, -2, -1)); // OR // $sharpenMatrix = array // ( // array(-1.2, -1, -1.2), // array(-1, 20, -1), // array(-1.2, -1, -1.2) // ); // $divisor = array_sum(array_map('array_sum', $sharpenMatrix)); // OR // $sharpen = array( // array(0.0, -1.0, 0.0), // array(-1.0, 5.0, -1.0), // array(0.0, -1.0, 0.0) // ); // $divisor = array_sum(array_map('array_sum', $sharpen)); // OR // $matrix = array( // array(-1, -1, -1), // array(-1, 16, -1), // array(-1, -1, -1), // ); // $divisor = array_sum(array_map('array_sum', $matrix)); @ImageConvolution($destination, $sharpness_transformation_matrix, $sharpness_factor, 0); } // Check and ensure that cache directory is setup OK. $cache_path = dirname($cache_file); if (!adaptive_images_script_ensure_cache_directory_ready($cache_path)) { return array('success' => false, 'message' => 'Cache directory for image not accessible or writeable.'); } // Save resized image in cache. switch ($extension) { case 'png': $png_compression_level = 6; $image_saved = @ImagePng($destination, $cache_file, $png_compression_level, PNG_FILTER_NONE); break; case 'gif': $image_saved = @ImageGif($destination, $cache_file); break; default: $image_saved = @ImageJpeg($destination, $cache_file, $jpg_quality); break; } // Cleanup destination image from memory. @ImageDestroy($destination); // Check if all OK. if (!$image_saved && !file_exists($cache_file)) { return array('success' => false, 'message' => 'Resized image could not be created.'); } // Return file of resized and cached image. return array('success' => true, 'message' => $cache_file); }
/** * @param array $options * @param array $info * * @return bool|null */ public function makeThumbnail($options = array(), array $info) { if (!class_exists('modPhpThumb')) { /** @noinspection PhpIncludeInspection */ require MODX_CORE_PATH . 'model/phpthumb/modphpthumb.class.php'; } /** @noinspection PhpParamsInspection */ $phpThumb = new modPhpThumb($this->xpdo); $phpThumb->initialize(); $tf = tempnam(MODX_BASE_PATH, 'ms2g_'); file_put_contents($tf, $info['content']); $phpThumb->setSourceFilename($tf); foreach ($options as $k => $v) { $phpThumb->setParameter($k, $v); } if ($phpThumb->GenerateThumbnail()) { ImageInterlace($phpThumb->gdimg_output, true); if ($phpThumb->RenderOutput()) { @unlink($phpThumb->sourceFilename); @unlink($tf); $this->xpdo->log(modX::LOG_LEVEL_INFO, '[ms2Gallery] phpThumb messages for "' . $this->get('url') . '". ' . print_r($phpThumb->debugmessages, 1)); return $phpThumb->outputImageData; } } @unlink($phpThumb->sourceFilename); @unlink($tf); $this->xpdo->log(modX::LOG_LEVEL_ERROR, '[ms2Gallery] Could not generate thumbnail for "' . $this->get('url') . '". ' . print_r($phpThumb->debugmessages, 1)); return false; }
function OutputThumbnail() { if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) { $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__); return false; } if (headers_sent()) { return $this->ErrorImage('OutputThumbnail() failed - headers already sent'); exit; } if ($this->down) { $downloadfilename = ereg_replace('[/\\:\\*\\?"<>|]', '_', $this->down); if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) { $downloadfilename = trim($downloadfilename, '.'); } if ($downloadfilename != $this->down) { $this->DebugMessage('renaming output file for "down" from "' . $this->down . '" to "' . $downloadfilename . '"', __FILE__, __LINE__); } if ($downloadfilename) { header('Content-Disposition: attachment; filename="' . $downloadfilename . '"'); } else { $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__); } } if ($this->useRawIMoutput) { header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $this->IMresizedData; } else { $this->DebugMessage('ImageInterlace($this->gdimg_output, ' . intval($this->config_output_interlace) . ')', __FILE__, __LINE__); ImageInterlace($this->gdimg_output, intval($this->config_output_interlace)); switch ($this->thumbnailFormat) { case 'jpeg': header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality); break; case 'png': case 'gif': header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); $ImageOutFunction = 'image' . $this->thumbnailFormat; @$ImageOutFunction($this->gdimg_output); break; case 'bmp': if (!@(include_once dirname(__FILE__) . '/phpthumb.bmp.php')) { $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.bmp.php" which is required for BMP format output', __FILE__, __LINE__); return false; } $phpthumb_bmp = new phpthumb_bmp(); if (is_object($phpthumb_bmp)) { $bmp_data = $phpthumb_bmp->GD2BMPstring($this->gdimg_output); unset($phpthumb_bmp); if (!$bmp_data) { $this->DebugMessage('$phpthumb_bmp->GD2BMPstring() failed', __FILE__, __LINE__); return false; } header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $bmp_data; } else { $this->DebugMessage('new phpthumb_bmp() failed', __FILE__, __LINE__); return false; } break; case 'ico': if (!@(include_once dirname(__FILE__) . '/phpthumb.ico.php')) { $this->DebugMessage('Error including "' . dirname(__FILE__) . '/phpthumb.ico.php" which is required for ICO format output', __FILE__, __LINE__); return false; } $phpthumb_ico = new phpthumb_ico(); if (is_object($phpthumb_ico)) { $arrayOfOutputImages = array($this->gdimg_output); $ico_data = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages); unset($phpthumb_ico); if (!$ico_data) { $this->DebugMessage('$phpthumb_ico->GD2ICOstring() failed', __FILE__, __LINE__); return false; } header('Content-Type: ' . phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat)); echo $ico_data; } else { $this->DebugMessage('new phpthumb_ico() failed', __FILE__, __LINE__); return false; } break; default: $this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "' . $this->thumbnailFormat . '" is not valid', __FILE__, __LINE__); return false; break; } } return true; }
/** * make thumbnail image and save */ function thumbnail($file, $save_filename, $max_width = 100, $max_height = 100, $sizeChg = 1) { $img_info = @getimagesize($file); //이미지 사이즈를 확인합니다. //이미지 타입을 이용해 변수를 재지정해줍니다. //------------------------------------------------------ // Imagetype Constants //------------------------------------------------------ // 1 IMAGETYPE_GIF // 2 IMAGETYPE_JPEG // 3 IMAGETYPE_PNG // 4 IMAGETYPE_SWF // 5 IMAGETYPE_PSD // 6 IMAGETYPE_BMP // 7 IMAGETYPE_TIFF_II (intel byte order) // 8 IMAGETYPE_TIFF_MM (motorola byte order) // 9 IMAGETYPE_JPC // 10 IMAGETYPE_JP2 // 11 IMAGETYPE_JPX // 12 IMAGETYPE_JB2 // 13 IMAGETYPE_SWC // 14 IMAGETYPE_IFF // 15 IMAGETYPE_WBMP // 16 IMAGETYPE_XBM //------------------------------------------------------ if ($img_info[2] == 1) { $src_img = ImageCreateFromGIF($file); } elseif ($img_info[2] == 2) { $src_img = ImageCreateFromJPEG($file); } elseif ($img_info[2] == 3) { $src_img = ImageCreateFromPNG($file); } elseif ($img_info[2] == 4) { $src_img = ImageCreateFromWBMP($file); } else { return false; } $img_info = getImageSize($file); //원본이미지의 정보를 얻어옵니다 $img_width = $img_info[0]; $img_height = $img_info[1]; $crt_width = $max_width; //생성되면 이미지 사이즈 $crt_height = $max_height; //1.가로 세로 원본비율을 맞추고, 남은 영역에 색채워서 정해진 크기로 생성 if ($sizeChg == 1) { if ($img_width / $max_width == $img_height / $max_height) { //원본과 썸네일의 가로세로비율이 같은경우 $dst_x = 0; $dst_y = 0; $dst_width = $max_width; $dst_height = $max_height; } elseif ($img_width / $max_width < $img_height / $max_height) { //세로에 기준을 둔경우 $dst_x = ($max_width - $img_width * ($max_height / $img_height)) / 2; $dst_y = 0; $dst_width = $max_height * ($img_width / $img_height); $dst_height = $max_height; } else { //가로에 기준을 둔경우 $dst_x = 0; $dst_y = ($max_height - $img_height * ($max_width / $img_width)) / 2; $dst_width = $max_width; $dst_height = $max_width * ($img_height / $img_width); } //2.가로 세로 원본비율을 맞추고, 남은 영역없이 이미지만 컷 생성 } else { if ($sizeChg == 2) { if ($img_width / $max_width == $img_height / $max_height) { //원본과 썸네일의 가로세로비율이 같은경우 $dst_width = $max_width; $dst_height = $max_height; } elseif ($img_width / $max_width < $img_height / $max_height) { //세로에 기준을 둔경우 $dst_width = $max_height * ($img_width / $img_height); $dst_height = $max_height; } else { //가로에 기준을 둔경우 $dst_width = $max_width; $dst_height = $max_width * ($img_height / $img_width); } $dst_x = 0; $dst_y = 0; $crt_width = $dst_width; $crt_height = $dst_height; //3.가로 세로 원본비율을 맞추지 않고, 정해진 크기대로 생성 } else { $dst_width = $max_width; $dst_height = $max_height; $dst_x = 0; $dst_y = 0; } } $dst_img = imagecreatetruecolor($crt_width, $crt_height); //타겟이미지를 생성합니다 $white = imagecolorallocate($dst_img, 255, 255, 255); imagefill($dst_img, 0, 0, $white); ImageCopyResized($dst_img, $src_img, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $img_width, $img_height); //타겟이미지에 원하는 사이즈의 이미지를 저장합니다 ImageInterlace($dst_img); switch ($img_info[2]) { case "1": ImageGIF($dst_img, $save_filename); break; case "2": ImageJPEG($dst_img, $save_filename); break; case "3": imagealphablending($dst_img, false); imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, 0, 0, $dst_width, $dst_height, $img_width, $img_height); //(생성이미지,원소스이미지,시작점X,시작점Y,원본소스상 시작점X,원본소스상 시작점Y,생성이미지너비, 생성이미지높이,원이미지너비,원이미지높이) imagesavealpha($dst_img, true); ImagePNG($dst_img, $save_filename, 0); break; case "4": ImageWBMP($dst_img, $save_filename); break; } ImageDestroy($dst_img); ImageDestroy($src_img); }
function gdRotate ($src, $dest, $rtt){ $src_img = ''; if(preg_match("/\.(png|gif|jpe?g|bmp)$/i", $src, $regs)) { switch($regs[1]) { case 'png': if (function_exists('ImageCreateFromPNG')) { $src_img=ImageCreateFromPNG($src); $save = 'imagepng'; } break; case 'gif': if (function_exists('ImageCreateFromGIF')) { $src_img=ImageCreateFromGIF($src); $save = 'imagegif'; } break; case 'jpeg': case 'jpg': if (function_exists('ImageCreateFromJPEG')) { $src_img=ImageCreateFromJPEG($src); $save = 'Imagejpeg'; } break; case 'bmp': if (function_exists('ImageCreateFromWBMP')) { $src_img=@ImageCreateFromWBMP($src); $save = 'imagewbmp'; } break; } } if (!$src_img) { spip_log("gdrotate: image non lue, $src"); return false; } $size=@getimagesize($src); if (!($size[0] * $size[1])) return false; if (function_exists('imagerotate')) { $dst_img = imagerotate($src_img, -$rtt, 0); } else { // Creer l'image destination (hauteur x largeur) et la parcourir // pixel par pixel (un truc de fou) if ($rtt == 180) $size_dest = $size; else $size_dest = array($size[1],$size[0]); if ($GLOBALS['meta']['image_process'] == "gd2") $dst_img=ImageCreateTrueColor($size_dest[0],$size_dest[1]); else $dst_img=ImageCreate($size_dest[0],$size_dest[1]); // t=top; b=bottom; r=right; l=left for ($t=0;$t<=$size_dest[0]-1; $t++) { $b = $size_dest[0] -1 - $t; for ($l=0;$l<=$size_dest[1]-1; $l++) { $r = $size_dest[1] -1 - $l; switch ($rtt) { case 90: imagecopy($dst_img,$src_img,$t,$r,$r,$b,1,1); break; case 270: imagecopy($dst_img,$src_img,$t,$l,$r,$t,1,1); break; case 180: imagecopy($dst_img,$src_img,$t,$l,$b,$r,1,1); break; } } } } ImageDestroy($src_img); ImageInterlace($dst_img,0); // obligatoire d'enregistrer dans le meme format, puisqu'on change le doc // mais pas son extension $save($dst_img,$dest); }