resize an <img> to 200*100
10775
function resize(url, type) {
  var img = new Image();
  display.innerHTML = '';
  img.onload= function () {
    var data = resizeImage.resize(img, 200, 100, type);
    var smallImg = new Image();
    display.appendChild(smallImg);
    smallImg.src = data;
  };
  display.appendChild(img);
  img.src = url;
}
158202
def get(img, light=False):
    """"""
    cols = gen_colors(img)
    return adjust(cols, light)
217782
def resize_avatar(self, img, base_width):
        
        w_percent = (base_width / float(img.size[0]))
        h_size = int((float(img.size[1]) * float(w_percent)))
        img = img.resize((base_width, h_size), PIL.Image.ANTIALIAS)
        return img
300808
def resize_program_image(img_url, img_size=300):
    '''
    
    '''
    match = re.match(r'.+/(\d+)x(\d+)/.+', img_url)
    if not match:
        _LOGGER.warning('Could not compute current image resolution of %s',
                        img_url)
        return img_url
    res_x = int(match.group(1))
    res_y = int(match.group(2))
    # aspect_ratio = res_x / res_y
    target_res_y = int(img_size * res_y / res_x)
    return re.sub(
        r'{}x{}'.format(res_x, res_y),
        r'{}x{}'.format(img_size, target_res_y),
        img_url)
630330
function ImageResize(filePath) {
	var image = this;
	var defDimensions = Q.defer();
	var defFormat = Q.defer();

	image.gm = gm(filePath)
		.size(function (err, value) {
			image.dimensions = value;
			defDimensions.resolve();
		})
		.format(function (err, value) {
			image.format = value;
			defFormat.resolve();
		});

	image.isLoaded = Q.all([defDimensions.promise, defFormat.promise]);
}
47013
def scale_image(self):
        """"""
        new_width = int(self.figcanvas.fwidth *
                        self._scalestep ** self._scalefactor)
        new_height = int(self.figcanvas.fheight *
                         self._scalestep ** self._scalefactor)
        self.figcanvas.setFixedSize(new_width, new_height)
455869
def gen_image(img, width, height, outfile, img_type='grey'):
    """"""
    assert len(img) == width * height or len(img) == width * height * 3

    if img_type == 'grey':
        misc.imsave(outfile, img.reshape(width, height))

    elif img_type == 'color':
        misc.imsave(outfile, img.reshape(3, width, height))
373452
def resize(image, target_size, **kwargs):
    """"""

    if isinstance(target_size, int):
        target_size = (target_size, target_size)

    if not isinstance(target_size, (list, tuple, np.ndarray)):
        message = (
            "`target_size` should be a single number (width) or a list"
            "/tuple/ndarray (width, height), not {}.".format(type(target_size))
        )
        raise ValueError(message)

    rank = len(image.shape)
    assert 3 <= rank <= 4

    original_size = image.shape[-3:-1]

    if original_size == target_size:
        return image  # noop return because ndimage.zoom doesn't check itself

    # TODO: maybe allow -1 in target_size to signify aspect-ratio preserving resize?
    ratios = [t / o for t, o in zip(target_size, original_size)]
    zoom = [1] * rank
    zoom[-3:-1] = ratios

    roughly_resized = ndimage.zoom(image, zoom, **kwargs)
    return roughly_resized[..., : target_size[0], : target_size[1], :]
184960
function getBackgroundSize(image) {
	var x = image.properties.width / image.ratio;
	var y = image.properties.height / image.ratio;
	var template = _.template('<%= x %>px <%= y %>px');

	return template({x: x, y: y});
}
637580
def scale_image(image, new_width):
    
    (original_width, original_height) = image.size
    aspect_ratio = original_height/float(original_width)
    new_height = int(aspect_ratio * new_width)

    # This scales it wider than tall, since characters are biased
    new_image = image.resize((new_width*2, new_height))
    return new_image
109046
function asGDImage($text,$resize=160){
        $barcode = $this->encode($text);
        $w  = $barcode['width'];
        $h  = $barcode['height'];
        $bs = 10;
        $size  = $bs * $w;

        $img   = imagecreatetruecolor($size + 2 * $bs * 2 ,$size + 2 * $bs * 2);
        $white = imagecolorallocate($img,255,255,255);
        $black = imagecolorallocate($img,0,0,0);
        imagefill($img,0,0,$white);

        for($j=0; $j < $h; $j++){
            for($i=0; $i < $w; $i++){
                $x1 = ($i * $bs) + $bs * 2;
                $y1 = ($size - (($j + 1) * $bs)) + $bs * 2;
                $x2 = $x1 + $bs;
                $y2 = $y1 + $bs;

                if($barcode['data'][$j * $w + $i]){
                    imagefilledrectangle($img,$x1,$y1,$x2,$y2,$black);
                } else {
                    imagefilledrectangle($img,$x1,$y1,$x2,$y2,$white);
                }
            }
        }

        if($resize == $size){
            return $img;
        }

        $new  = imagecreatetruecolor($resize,$resize);
        imagecopyresized($new, $img, 0, 0, 0, 0, $resize, $resize, $size + 2 * $bs * 2, $size + 2 * $bs * 2);
        imagedestroy($img);
        return $new;
    }
374839
def pad_image(arr, max_size=400):
    """"""
    dim = np.max(arr.shape)
    img = np.zeros((dim, dim, 3), dtype=arr.dtype)
    xl = (dim - arr.shape[0]) // 2
    yl = (dim - arr.shape[1]) // 2
    img[xl:arr.shape[0]+xl, yl:arr.shape[1]+yl, :] = arr
    return resample_image(img, max_size=max_size)
256832
function resize($new_width, $new_height)
    {
        $width = $this->width;
        $height = $this->height;

        if( $width > $height )
        {
            $new_height = ($new_width / $width) * $height;
        }
        elseif($height > $width)
        {
            $new_width = ($new_height / $height) * $width;
        }

        $image = imagecreatetruecolor( $new_width, $new_height );
        imagecopyresampled($image, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

        $this->width = imagesx($image);
        $this->height = imagesy($image);
        $this->image = $image;
    }
1047761
public static function resizeImage($image, $newWidth, $newHeight, $autoRotate = false, $mode = ImageTools::MODE_SCALE_CROP, $backgroundColor = 0x00000000)
    {
        $sourceWidth = imagesx($image);
        $sourceHeight = imagesy($image);

        $sourcePar = $sourceWidth / $sourceHeight;
        $newPar = $newWidth / $newHeight;
        $sourceX = $newX = 0;
        $sourceY = $newY = 0;

        if ($autoRotate && (($sourcePar > 1 && $newPar < 1) || ($sourcePar < 1 && $newPar > 1))) {
            $t = $newWidth;
            $newWidth = $newHeight;
            $newHeight = $t;
            $newPar = $newWidth / $newHeight;
        }

        $targetWidth = $newWidth;
        $targetHeight = $newHeight;

        // MODE_EXACT gets handled through default variables

        if ($mode == ImageTools::MODE_CROP) {
            if ($sourceWidth > $newWidth) {
                $sourceX = ($sourceWidth - $newWidth) >> 1;
                $sourceWidth = $newWidth;
            } else {
                $targetWidth = $sourceWidth;
                $newX = ($newWidth - $sourceWidth) >> 1;
            }

            if ($sourceHeight > $newHeight) {
                $sourceY = ($sourceHeight - $newHeight) >> 1;
                $sourceHeight = $newHeight;
            } else {
                $targetHeight = $sourceHeight;
                $newY = ($newHeight - $sourceHeight) >> 1;
            }

        } elseif ($mode == ImageTools::MODE_SCALE_CROP) {
            if ($sourcePar > $newPar) {
                $orgWidth = $sourceWidth;
                $sourceWidth = $sourceHeight * $newPar;
                $sourceX = ($orgWidth - $sourceWidth) >> 1;
            } else {
                $orgHeight = $sourceHeight;
                $sourceHeight = $sourceWidth / $newPar;
                $sourceY = ($orgHeight - $sourceHeight) >> 1;
            }

        } elseif ($mode == ImageTools::MODE_SCALE_PAD) {
            if ($sourcePar > $newPar) {
                $targetHeight = $targetWidth / $sourcePar;
                $newY = ($newHeight - $targetHeight) >> 1;
            } else {
                $targetWidth = $targetHeight * $sourcePar;
                $newX = ($newWidth - $targetWidth) >> 1;
            }
        } elseif ($mode == ImageTools::MODE_FIT) {
            if ($sourcePar > $newPar) {
                $targetHeight = $newHeight = round($newWidth / $sourcePar);
            } else {
                $targetWidth = $newWidth = round($newHeight * $sourcePar);
            }
        }

        $new = imagecreatetruecolor($newWidth, $newHeight);

        imagealphablending($new, false);

        $backgroundColor = self::colorHexToRgba($backgroundColor);
        $backgroundColor = imagecolorallocatealpha($new, $backgroundColor['r'], $backgroundColor['g'], $backgroundColor['b'], 127 - floor($backgroundColor['a'] / 2));

        imagefilledrectangle($new, 0, 0, $newWidth, $newHeight, $backgroundColor);

        imagesavealpha($new, true);

        imagecopyresampled($new, $image, $newX, $newY, $sourceX, $sourceY, $targetWidth, $targetHeight, $sourceWidth, $sourceHeight);

        return $new;
    }
793804
function resizeImage(img, max_width, max_height) {
    var sizes = this.getImageNewAspectSizes(img, max_width, max_height);
    var width = sizes.width;
    var height = sizes.height;
    var canvas = this.imageToCanvas(img, width, height);
    return canvas;
    //return this.getImageByCanvas(canvas);
  }
629070
def resize(self, width=None):
        
        (iw, ih) = self.size
        if width is None:
            width = min(iw, utils.term.width)
        elif isinstance(width, basestring):
            percents = dict([(pct, '%s%%' % (pct)) for pct in range(101)])
            width = percents[width]
        height = int(float(ih) * (float(width) / float(iw)))
        height //= 2
        self.img = self.img.resize((width, height))
89382
function resizeImage(options, callback) {
  var size = options.size.width + 'x' + options.size.height;
  if (!options.size.maintainratio) {
    size += '\\!';
  }
  var command = [
    options.convert,
    options.org,
    '-adaptive-resize',
    options.size.width + 'x' + options.size.height,
    options.path
    ].join(' ');

  /* Create folder if we have to. */
  var dest = lib.path.join(options.dest, options.size.name);
  if (!lib.fs.existsSync(dest)) {
    lib.fs.mkdirSync(dest);
  }

  /* Create resize */
  lib.exec(command, function (err, stdout, stderr) {
    callback(err, options.path);
  });
}