/*
Create multiple thumbs/resizes of an image
Path to the original
sizes
width, height, crop type, path, quality
353660
public function create($file, $path, $filename, $sizes)
    {
        $this->file = $file;

        if (is_array($sizes)) {
            $resized = array();

            foreach ($sizes as $size) {
                $this->new_width  = $size[0]; //$new_width;
                $this->new_height = $size[1]; //$new_height;
                $this->option     = $size[2]; //crop type

                //ensure that the directory path exists
                if (!is_dir($size[3])) {
                    mkdir($size[3]);
                }

                $resized[] = $this->do_resize($path.$filename, $size[3].$filename, $size[4]);
            }
        }

        return $resized;
    }
438898
private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos)
		# Author:     Jarrod Oberto
		# Date:       15-09-08
		# Purpose:    Crops the image
		# Param in:   $newWidth:
		#             $newHeight:
		# Param out:  n/a
		# Reference:
		# Notes:
		#
	{

		// *** Get cropping co-ordinates
		$cropArray = $this->getCropPlacing($optimalWidth, $optimalHeight, $newWidth, $newHeight, $cropPos);
		$cropStartX = $cropArray['x'];
		$cropStartY = $cropArray['y'];

		// *** Crop this bad boy
		$crop = imagecreatetruecolor($newWidth, $newHeight);
		$this->keepTransparancy($optimalWidth, $optimalHeight, $crop);
		imagecopyresampled($crop, $this->imageResized, 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight, $newWidth, $newHeight);

		$this->imageResized = $crop;

		// *** Set new width and height to our variables
		$this->width = $newWidth;
		$this->height = $newHeight;

	}
146588
def get_thumbnail(self, original, size, crop, options):
        
        try:
            image = self.create(original, size, crop, options)
        except ThumbnailError:
            image = None
        finally:
            self.cleanup(original)
        return image
477574
public function resizeCrop()
    {
        $sourceDimension = $this->sourceImageFile->getDimension();
        $resampleDimension = $this->resampleImageFile->getDimension();

        if ($resampleDimension->getOrientation() === 'SQUARE') {
            if ($sourceDimension->getOrientation() === 'LANDSCAPE') {
                $sourceSquareSize = $sourceDimension->getHeight();

                $sourceDimension = new Dimension(
                    $sourceSquareSize,
                    $sourceSquareSize,
                    ($sourceDimension->getWidth() - $sourceDimension->getHeight()) / 2,
                    0
                );
            } elseif ($sourceDimension->getOrientation() === 'PORTRAIT') {
                $sourceSquareSize = $sourceDimension->getWidth();

                $sourceDimension = new Dimension(
                    $sourceSquareSize,
                    $sourceSquareSize,
                    0,
                    ($sourceDimension->getHeight() - $sourceDimension->getWidth()) / 2
                );
            }
        } else {

            //try max width first...
            $resizeRatio = $resampleDimension->getWidth() / $sourceDimension->getWidth();
            $resizeWidth = $resampleDimension->getWidth();
            $resizeHeight = $sourceDimension->getHeight() * $resizeRatio;

            //if that didn't work
            if ($resizeHeight > $resampleDimension->getHeight()) {
                $resizeRatio = $resampleDimension->getHeight() / $sourceDimension->getHeight();
                $resizeHeight = $resampleDimension->getHeight();
                $resizeWidth = $sourceDimension->getWidth() * $resizeRatio;
            }

            switch ($resampleDimension->getFocus()) {
                default:
                case 'CENTER':

                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        ($sourceDimension->getWidth() / 2) - ($resizeWidth / 2),
                        ($sourceDimension->getHeight() / 2) - ($resizeHeight / 2)
                    );

                    break;
                case 'NORTH':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        ($sourceDimension->getWidth() - $resizeWidth) / 2,
                        0
                    );
                    break;
                case 'NORTHWEST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        0,
                        0
                    );
                    break;
                case 'NORTHEAST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        $sourceDimension->getWidth() - $resizeWidth,
                        0
                    );
                    break;
                case 'SOUTH':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        ($sourceDimension->getWidth() - $resizeWidth) / 2,
                        $sourceDimension->getHeight() - $resizeHeight
                    );
                    break;
                case 'SOUTHWEST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        0,
                        $sourceDimension->getHeight() - $resizeHeight
                    );
                    break;
                case 'SOUTHEAST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        $sourceDimension->getWidth() - $resizeWidth,
                        $sourceDimension->getHeight() - $resizeHeight
                    );
                    break;
                case 'WEST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        0,
                        ($sourceDimension->getHeight() - $resizeHeight) / 2
                    );
                    break;
                case 'EAST':
                    $sourceDimension = new Dimension(
                        $resizeWidth,
                        $resizeHeight,
                        $sourceDimension->getWidth() - $resizeWidth,
                        ($sourceDimension->getHeight() - $resizeHeight) / 2
                    );
                    break;
            }
        }

        $resampleAxis = $this->resampleImageFile->getDimension()->getAxis();
        $sourceAxis = $sourceDimension->getAxis();

        if (function_exists('imagecreatetruecolor')) {
            $this->resampleImageResource = imagecreatetruecolor(
                $resampleDimension->getWidth(),
                $resampleDimension->getHeight()
            );

            imagealphablending($this->resampleImageResource, false);
            imagesavealpha($this->resampleImageResource, true);

            $transparent = imagecolorallocatealpha($this->resampleImageResource, 255, 255, 255, 127);
            imagefilledrectangle($this->resampleImageResource, 0, 0, $resampleDimension->getWidth(),
                $resampleDimension->getHeight(), $transparent);

            return imagecopyresampled(
                $this->resampleImageResource,
                $this->sourceImageResource,
                $resampleAxis->getX(),
                $resampleAxis->getY(),
                $sourceAxis->getX(),
                $sourceAxis->getY(),
                $resampleDimension->getWidth(),
                $resampleDimension->getHeight(),
                $sourceDimension->getWidth(),
                $sourceDimension->getHeight()
            );
        } else {
            $this->resampleImageResource = imagecreate($resampleDimension->getWidth(),
                $resampleDimension->getHeight());

            imagealphablending($this->resampleImageResource, false);
            imagesavealpha($this->resampleImageResource, true);

            $transparent = imagecolorallocatealpha($this->resampleImageResource, 255, 255, 255, 127);
            imagefilledrectangle($this->resampleImageResource, 0, 0, $resampleDimension->getWidth(),
                $resampleDimension->getHeight(), $transparent);

            return imagecopyresized(
                $this->resampleImageResource,
                $this->sourceImageResource,
                $resampleAxis->getX(),
                $resampleAxis->getY(),
                $sourceAxis->getX(),
                $sourceAxis->getY(),
                $resampleDimension->getWidth(),
                $resampleDimension->getHeight(),
                $sourceDimension->getWidth(),
                $sourceDimension->getHeight()
            );
        }
    }
549595
private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOException {
		// Decode image file, compress and re-save it
		boolean saved = false;
		File targetFile = configuration.diskCache.get(uri);
		if (targetFile != null && targetFile.exists()) {
			ImageSize targetImageSize = new ImageSize(maxWidth, maxHeight);
			DisplayImageOptions specialOptions = new DisplayImageOptions.Builder().cloneFrom(options)
					.imageScaleType(ImageScaleType.IN_SAMPLE_INT).build();
			ImageDecodingInfo decodingInfo = new ImageDecodingInfo(memoryCacheKey,
					Scheme.FILE.wrap(targetFile.getAbsolutePath()), uri, targetImageSize, ViewScaleType.FIT_INSIDE,
					getDownloader(), specialOptions);
			Bitmap bmp = decoder.decode(decodingInfo);
			if (bmp != null && configuration.processorForDiskCache != null) {
				L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey);
				bmp = configuration.processorForDiskCache.process(bmp);
				if (bmp == null) {
					L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey);
				}
			}
			if (bmp != null) {
				saved = configuration.diskCache.save(uri, bmp);
				bmp.recycle();
			}
		}
		return saved;
	}
952249
function (img) {
                // set preview pane dimensions
                this.previewDimensions = this.calculateDimensions(img.width, img.height);
                this.previewCanvas.nativeElement.width = this.previewDimensions.width;
                this.previewCanvas.nativeElement.height = this.previewDimensions.height;
                this.imageResizeRatio = this.previewDimensions.width / img.width;
                this.imageDivStyle = {
                    width: this.previewDimensions.width + this.options.cropToolDimensions.width + 'px',
                    height: this.previewDimensions.height + this.options.cropToolDimensions.height + 'px',
                    'margin-left': "calc((100% - " + (this.previewDimensions.width + 10) + "px) / 2 + " + this.options.cropToolDimensions.width / 2 + "px)",
                    'margin-right': "calc((100% - " + (this.previewDimensions.width + 10) + "px) / 2 - " + this.options.cropToolDimensions.width / 2 + "px)",
                };
                this.limitsService.setPaneDimensions({ width: this.previewDimensions.width, height: this.previewDimensions.height });
            }
637709
def resize!
      begin
        image = MiniMagick::Image.open(@file.path)
        image.resize("#{@width}x#{@height}")
      rescue
        # Pass on any error
      else
        image.write(@file.path) rescue nil
      end
    end
1086689
def adjust_size(self, dst_x, dst_y, mode=FIT):
        
        # get image size
        image = Image.open(self.path)
        width, height = image.size
        if mode == FIT:
            return adjust_crop(dst_x, dst_y, width, height)
232268
function(callback) {
      var firstThumbnail;

      for (var i = 0; i < thumbnailsPaths.length; i++) {
        var thumbnailsPath = thumbnailsPaths[i].thumbnailPath;

        if (!firstThumbnail)
          firstThumbnail = gm(thumbnailsPath);
        else
          firstThumbnail.append(thumbnailsPath, horizontally);

        images.push({
          sprite: destinationPath,
          image: thumbnailsPaths[i].originalPath,
          x: horizontally ? width * i : 0,
          y: horizontally ? 0 : height * i
        });
      }
      firstThumbnail
        .quality(quality)
        .write(destinationPath, callback);
    }
1256155
public function resize()
    {
        $src = $this->rootDir.DS.str_replace(['/', '\\'], DS, $this->imagePath);   /* read the source image */

        if (!file_exists($src)) {
            throw new \Exception("File not found in given path $src.");
        }

        $info = getimagesize($src); // get the image size
        $path = pathinfo($src);
        $extension = strtolower($path['extension']);

        if (!in_array($extension, $this->imageTypes)) {
            throw new \Exception('File type not supported!');
        }

        $thumbName = is_null($this->thumbName)
            ? $path['basename']
            : $this->thumbName.'.'.$path['extension'];

        $sourceImage = $this->imageCreateFrom(($extension == 'gif') ? 'jpeg' : $extension, $src);
        $thumbImg = $this->changeDimensions($sourceImage, $this->fixedWidth, $this->fixedHeight);
        $this->image($extension, $thumbImg, $thumbName);

        return true;
    }
1305026
public function resize( $path, $name , $width = null , $height = null)
    {

        $img = \Image::make($path);

        // prevent possible upsizing
        $img->resize($width, $height, function ($constraint) {
            $constraint->aspectRatio();
            $constraint->upsize();
        });

        $img->save($path);
	}
487471
public function resizeImage($savePath, $image, $newImageName, $width, $height)
    {
        
        $fileImage = $image;
        $outputImg = null;
        $ext = pathinfo($newImageName, PATHINFO_EXTENSION);

        $thumb = imagecreatetruecolor($width, $height);
        list($w, $h) = getimagesize($fileImage);

        switch(exif_imagetype($fileImage)) {
            case IMAGETYPE_GIF:
                $image = imagecreatefromgif($fileImage);
            break;
            case IMAGETYPE_JPEG:
                $image = imagecreatefromjpeg($fileImage);
            break;
            case IMAGETYPE_PNG:
                $image = imagecreatefrompng($fileImage);
            break;
        }
        
        imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, $w, $h);

        switch ($ext) {
            case self::EXT_PNG:
                $outputImg = imagepng($thumb, $savePath.'/'.$newImageName, 9);
                break;
            case self::EXT_GIF:
                $outputImg = imagegif($thumb, $savePath.'/'.$newImageName);
                break;
            case self::EXT_JPG:
                $outputImg = imagejpeg($thumb, $savePath.'/'.$newImageName, 100);
                break;
        }

        imagedestroy($thumb);
    
    }
1168856
public function cropAndResize($filePath, $x, $y, $h, $w, array $format)
    {
        $image = $this->imagickFactory->create($filePath);
        $image->cropImage($w, $h, $x, $y);
        $image = $this->resizeImage($format, $image);

        $pathInfo = pathinfo($filePath);
        $croppedFilePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR . time() . $pathInfo['basename'];

        $this->saveImage($croppedFilePath, $image, $format['compression_quality']);

        return $croppedFilePath;
    }
997121
function(fileId, imgOrCanvas, maxSize, fromServer, customResizeFunction) {
            var promiseToReturn = new qq.Promise(),
                fileOrUrl, options;

            if (this._imageGenerator) {
                fileOrUrl = this._thumbnailUrls[fileId];
                options = {
                    customResizeFunction: customResizeFunction,
                    maxSize: maxSize > 0 ? maxSize : null,
                    scale: maxSize > 0
                };

                // If client-side preview generation is possible
                // and we are not specifically looking for the image URl returned by the server...
                if (!fromServer && qq.supportedFeatures.imagePreviews) {
                    fileOrUrl = this.getFile(fileId);
                }

                /* jshint eqeqeq:false,eqnull:true */
                if (fileOrUrl == null) {
                    promiseToReturn.failure({container: imgOrCanvas, error: "File or URL not found."});
                }
                else {
                    this._imageGenerator.generate(fileOrUrl, imgOrCanvas, options).then(
                        function success(modifiedContainer) {
                            promiseToReturn.success(modifiedContainer);
                        },

                        function failure(container, reason) {
                            promiseToReturn.failure({container: container, error: reason || "Problem generating thumbnail"});
                        }
                    );
                }
            }
            else {
                promiseToReturn.failure({container: imgOrCanvas, error: "Missing image generator module"});
            }

            return promiseToReturn;
        }
1048373
function image_resize( $file, $max_w, $max_h, $crop = false, $far = false, $iar = false, $dest_path = null, $jpeg_quality = 90 ) {
		$image = wp_load_image( $file );
		if ( !is_resource( $image ) )
			return new WP_Error('error_loading_image', $image);

		$size = @getimagesize( $file );
		if ( !$size )
				return new WP_Error('invalid_image', __('Could not read image size'), $file);
		list($orig_w, $orig_h, $orig_type) = $size;
		
		$dims = mf_image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop, $far, $iar);
		
		if ( !$dims ){
			$dims = array(0,0,0,0,$orig_w,$orig_h,$orig_w,$orig_h);
		}
		list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;

    $newimage = imagecreatetruecolor( $dst_w, $dst_h );
    imagealphablending($newimage, false);
    imagesavealpha($newimage, true);
    $transparent = imagecolorallocatealpha($newimage, 255, 255, 255, 127);
    imagefilledrectangle($newimage, 0, 0, $dst_w, $dst_h, $transparent);
    imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);

		// convert from full colors to index colors, like original PNG.
		if ( IMAGETYPE_PNG == $orig_type && !imageistruecolor( $image ) )
			imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );

		// we don't need the original in memory anymore
		imagedestroy( $image );
		$info = pathinfo($dest_path);
		$dir = $info['dirname'];
		$ext = $info['extension'];
		$name = basename($dest_path, ".{$ext}");
		
		$destfilename = "{$dir}/{$name}.{$ext}";
		
		if ( IMAGETYPE_GIF == $orig_type ) {
 			if ( !imagegif( $newimage, $destfilename ) )
				return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
		} elseif ( IMAGETYPE_PNG == $orig_type ) {
			if ( !imagepng( $newimage, $destfilename ) )
				return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
		} else {
			// all other formats are converted to jpg
                  //Todo: add option for use progresive JPG
                  //imageinterlace($newimage, true); //Progressive JPG 
                  if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
                    return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
		}

		imagedestroy( $newimage );

		// Set correct file permissions
		$stat = stat( dirname( $destfilename ));
		$perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits
		@ chmod( $destfilename, $perms );

		return $destfilename;
	}
1322393
function (res, name, version) {
  //Options
  var imgPath, width;
  //RegExp
  var re = /^\d\.\d.\d$/;
  //Test version
  if (re.test(version)) {
    imgPath = path.join(dir, name + '.png');
    width = 76;
  } else if (version.length === 6) {
    imgPath = path.join(dir, name + '-larger.png');
    width = 80;
  } else if (version.length === 7) {
    imgPath = path.join(dir, name + '-larger.png');
    width = 77;
  } else {
    imgPath = path.join(dir, name + '-larger.png');
    width = 74;
  }

  //Create Image
  var base = gm(imgPath)
    .font(path.join(__dirname, 'fonts', 'Arial.ttf'))
    .fontSize(10)
    .fill('#ffffff')
    .drawText(width, 12, version);
  //Write Stream and send to client
  write(base, res);
}
45984
def resize(img, width, height):
    
    return img.resize((width, height), Image.ANTIALIAS)