Set image dimensions from the cached dimensions of a ``Thumbnail``
        model instance.
325273
def set_image_dimensions(self, thumbnail):
        
        try:
            dimensions = getattr(thumbnail, 'dimensions', None)
        except models.ThumbnailDimensions.DoesNotExist:
            dimensions = None
        if not dimensions:
            return False
        self._dimensions_cache = dimensions.size
        return self._dimensions_cache
705603
def image_scale(xscale=1.0, yscale=1.0, axes="gca"):
    
    if axes == "gca": axes = _pylab.gca()

    e = axes.images[0].get_extent()
    x1 = e[0]*xscale
    x2 = e[1]*xscale
    y1 = e[2]*yscale
    y2 = e[3]*yscale

    image_set_extent([x1,x2],[y1,y2], axes)
426209
def set_thumbnail(self, thumbnail):
        
        self.thumbnail = thumbnail
        if isinstance(self.thumbnail, str):
            from .files import ThumbnailFile
            self.thumbnail = ThumbnailFile(path=self.thumbnail)

        if self.thumbnail:
            self.add_file(self.thumbnail)
501670
protected function resize()
    {
        $config = config('image', true);

        if ( ! empty($this->imageQuality)) {
            $config->offsetSet('quality', intval($this->imageQuality));
        }

        if ($config->cached === true) {
            if ($this->imageFilePath !== $this->imageNotFoundFilename) {
                $cacheImageKey = 'image-' . ($this->input->get('crop') ? 'crop-' : '') . implode('x',
                        $this->imageSize) . '-' . str_replace($this->storagePath, '', $this->imageFilePath);

                if (cache()->hasItemPool('images')) {
                    $cacheItemPool = cache()->getItemPool('images');

                    if ($cacheItemPool->hasItem($cacheImageKey)) {
                        $cacheImageString = $cacheItemPool->getItem($cacheImageKey)->get();

                        $manipulation = new Manipulation($config);
                        $manipulation->setImageFile($this->imageFilePath);
                        $manipulation->setImageString($cacheImageString);
                        $manipulation->displayImage(intval($this->imageQuality), $this->imageFileMime);
                    } else {
                        $manipulation = new Manipulation($config);
                        $manipulation->setImageFile($this->imageFilePath);
                        $manipulation->resizeImage($this->imageSize[ 'width' ], $this->imageSize[ 'height' ],
                            (bool)$this->imageCrop);
                        $cacheItemPool->save(new Item($cacheImageKey, $manipulation->getBlobImage(), false));

                        $manipulation->displayImage(intval($this->imageQuality), $this->imageFileMime);
                        exit(EXIT_SUCCESS);
                    }
                }
            }
        }

        $manipulation = new Manipulation($config);
        $manipulation->setImageFile($this->imageFilePath);
        $manipulation->resizeImage($this->imageSize[ 'width' ], $this->imageSize[ 'height' ], (bool)$this->imageCrop);
        $manipulation->displayImage(intval($this->imageQuality), $this->imageFileMime);
        exit(EXIT_SUCCESS);
    }
437593
def resize_compute_width_height(fullfile,_megapixels):
    """"""

    img = Image.open(fullfile)
    width,height=img.size

    current_megapixels=width*height/(2.0**20)
    scale=sqrt(_megapixels/float(current_megapixels))

    logger.debug('A resize scale would be %f'%(scale))
    # Can't make bigger, return original
    if scale>= 1.0:
        logger.warning('Image is %0.1f MP, trying to scale to %0.1f MP - just using original!',
                current_megapixels,_megapixels);
        return width,height

    new_width=int(width*scale)
    new_height=int(height*scale)

    return new_width,new_height
1166783
def set_image(self, **kwargs):
        
        self.image = {
            'url': kwargs.get('url'),
            'proxy_url': kwargs.get('proxy_url'),
            'height': kwargs.get('height'),
            'width': kwargs.get('width'),
        }
677919
def _initializeDimensions(self, inputData):
    
    if len(inputData.shape) == 2:
      self.imageHeight, self.numImages = inputData.shape
      self.imageWidth, self.numChannels = None, None

    elif len(inputData.shape) == 3:
      self.imageHeight, \
      self.imageWidth, \
      self.numImages = inputData.shape
      self.numChannels = None

    elif len(inputData.shape) == 4:
      self.imageHeight, \
      self.imageWidth, \
      self.numChannels, \
      self.numImages = inputData.shape

    else:
      raise ValueError("The provided image set has more than 4 dimensions.")
31167
def get_image_size(self, image):
        
        if image['size'] is None:
            args = settings.THUMBNAIL_VIPSHEADER.split(' ')
            args.append(image['source'])
            p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            p.wait()
            m = size_re.match(str(p.stdout.read()))
            image['size'] = int(m.group('x')), int(m.group('y'))
        return image['size']
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
136945
def set_moving_image(self, image):
        
        if not isinstance(image, iio.ANTsImage):
            raise ValueError('image must be ANTsImage type')

        if image.dimension != self.dimension:
            raise ValueError('image dim (%i) does not match metric dim (%i)' % (image.dimension, self.dimension))

        self._metric.setMovingImage(image.pointer, False)
        self.moving_image = image
989394
def rescale(img, size, mode=None):
    

    assert size[0] or size[1], "Must provide a width or a height"

    size = list(size)
    crop = size[0] and size[1]

    if not size[0]:
        size[0] = int(img.size[0] * size[1] / float(img.size[1]))
    if not size[1]:
        size[1] = int(img.size[1] * size[0] / float(img.size[0]))

    if crop:
        b = img.size[0] > img.size[1]
        crop_size = (img.size[b], int(img.size[b] * size[0] / float(size[1])))

        if mode ==  CROP_TL:
            img = img.crop((0, 0, crop_size[0], crop_size[1]))
        elif mode == CROP_BR:
            img = img.crop((
                img.size[0] - crop_size[0],
                img.size[1] - crop_size[1],
                img.size[0],
                img.size[1]
            ))

    return img.resize(size, Image.ANTIALIAS)
572984
def size_from_name(size, sizes):

    """"""

    by_name = [s for s in sizes if s.name == size]
    if len(by_name) > 1:
        raise Exception('more than one image named %s exists' % size)
    return by_name[0]
676373
def _thumbnail_resize(self, image, thumb_size, crop=None, bg=None):
        """"""

        if crop == 'fit':
            img = ImageOps.fit(image, thumb_size, Image.ANTIALIAS)
        else:
            img = image.copy()
            img.thumbnail(thumb_size, Image.ANTIALIAS)

        if bg:
            img = self._bg_square(img, bg)

        return img
836369
def __make_thumbnail(self, width, height):
        
        (w, h) = self.size
        factor = max(
            (float(w) / width),
            (float(h) / height)
        )
        w /= factor
        h /= factor
        return self.get_image((round(w), round(h)))
445849
def resize(fname, basewidth, opFilename):
    
    if basewidth == 0:
        basewidth = 300
    img = Image.open(fname)
    wpercent = (basewidth/float(img.size[0]))
    hsize = int((float(img.size[1])*float(wpercent)))
    img = img.resize((basewidth,hsize), Image.ANTIALIAS)
    img.save(opFilename)
637241
def resize_lazy(image, width=None, height=None, crop=False, force=False,
                namespace="resized", storage=default_storage,
                as_url=False):
    
    # First normalize params to determine which file to get
    width, height, crop = _normalize_params(image, width, height, crop)
    # Fetch the name of the resized image so i can test it if exists
    name = _get_resized_name(image, width, height, crop, namespace)

    # Fetch storage if an image has a specific storage
    try:
        storage = image.storage
    except AttributeError:
        pass

    # Test if exists or force
    if force or not storage.exists(name):
        resized_image = None
        try:
            resized_image = resize(image, width, height, crop)
            name = storage.save(name, resized_image)
        finally:
            if resized_image is not None:
                resized_image.close()

    if as_url:
        return storage.url(name)

    return name
45984
def resize(img, width, height):
    
    return img.resize((width, height), Image.ANTIALIAS)