/* Given an array of various sizes of the same image and a container width,
return the best image.
488272
function (containerWidth, containerHeight, imageSizes) {

      var devicePixelRatio = window.devicePixelRatio || 1;
      var deviceOrientation = getDeviceOrientation();
      var windowOrientation = getWindowOrientation();
      var wrapperOrientation = (containerHeight > containerWidth) ?
        'portrait' :
        (containerWidth > containerHeight ? 'landscape' : 'square');

      var lastAllowedImage = 0;
      var testWidth;

      for (var j = 0, image; j < imageSizes.length; j++) {

        image = imageSizes[j];

        // In case a new image was pushed in, process it:
        if (typeof image === 'string') {
          image = imageSizes[j] = {url: image};
        }

        if (image.pixelRatio && image.pixelRatio !== 'auto' && parseFloat(image.pixelRatio) !== devicePixelRatio) {
          // We disallowed choosing this image for current device pixel ratio,
          // So skip this one.
          continue;
        }

        if (image.deviceOrientation && image.deviceOrientation !== deviceOrientation) {
          // We disallowed choosing this image for current device orientation,
          // So skip this one.
          continue;
        }

        if (image.windowOrientation && image.windowOrientation !== deviceOrientation) {
          // We disallowed choosing this image for current window orientation,
          // So skip this one.
          continue;
        }

        if (image.orientation && image.orientation !== wrapperOrientation) {
          // We disallowed choosing this image for current element's orientation,
          // So skip this one.
          continue;
        }

        // Mark this one as the last one we investigated
        // which does not violate device pixel ratio rules.
        // We may choose this one later if there's no match.
        lastAllowedImage = j;

        // For most images, we match the specified width against element width,
        // And enforcing a limit depending on the "pixelRatio" property if specified.
        // But if a pixelRatio="auto", then we consider the width as the physical width of the image,
        // And match it while considering the device's pixel ratio.
        testWidth = containerWidth;
        if (image.pixelRatio === 'auto') {
          containerWidth *= devicePixelRatio;
        }

        // Stop when the width of the image is larger or equal to the container width
        if (image.width >= testWidth) {
          break;
        }
      }

      // Use the image located at where we stopped
      return imageSizes[Math.min(j, lastAllowedImage)];
    }
42960
public function getImage()
    {
        $this->imageWidth = null;
        $this->imageHeight = null;

        $images = $this->images;
        $bigger = (bool) $this->getConfig('choose_bigger_image');
        $minWidth = $this->getConfig('min_image_width', 1);
        $minHeight = $this->getConfig('min_image_height', 1);

        $images = array_filter($images, function ($image) use ($minWidth, $minHeight) {
            return $image['width'] >= $minWidth && $image['height'] >= $minHeight;
        });

        if (empty($images)) {
            return null;
        }

        reset($images);
        $image = current($images);

        if ($bigger) {
            $sizes = [];

            foreach ($images as $img) {
                $sizes[$img['url']] = $img['size'];
            }

            $biggest = static::getBigger($sizes);

            foreach ($images as $img) {
                if ($biggest == $img['url']) {
                    $image = $img;
                    break;
                }
            }
        }

        $this->imageWidth = $image['width'];
        $this->imageHeight = $image['height'];

        return $image['url'];
    }
36769
def image2array(image):
    
    nx, ny = image.shape  # find the size of the array
    imgh = np.reshape(image, nx*ny)  # change the shape to be 1d
    return imgh
921227
function ImageComparison (options) {
        this.options = utils.extend({}, [defaultOptions, options], {
            clearEmpty: true
        });
        this.container = this.options.container;
        this.images = [this.options.data[0].image, this.options.data[1].image];
        this.labels = [this.options.data[0].label, this.options.data[1].label];
        this._animateInterval = null;
        this._comparisonSeparator = null;
        this._items = [];

        if (this.container == null) {
            console.error('Container element not found!')
        }

        if (!this.images[0] || !this.images[1]) {
            console.error('Need two images!')
        }

        this._build();
        this._setEvents();
    }
1194186
function() {
        var min_size = Infinity;
        var index = null;
        for (var i = 0; i < this.bound_textures.length; i++) {
            var t = this.bound_textures[i];
            if (t.size < min_size) {
                min_size = t.size;
                index = i;
            }
        }
        return index;
    }
1178460
def image2array(self, image):
        
        idex_mask = self._idex_mask
        array = util.image2array(image)
        if self._idex_mask_bool is True:
            return array[idex_mask == 1]
        else:
            return array
415242
private function getAdjustedImageDimensions(Image $image, int $width, int $height, bool $crop = false): array
    {
        if ($image->getWidth() / $image->getHeight() > $width / $height) {		// current is wider than new
            if (true === $crop) {	// upscale prevention
                return [
                    'width' => $this->getImageWidth($image, $height),
                    'height' => $height,
                ];
            } else {
                return [
                    'width' => $width,
                    'height' => $this->getImageHeight($image, $width),
                ];
            }
        } elseif ($image->getWidth() / $image->getHeight() < $width / $height) {	// current is taller than new
            if (true === $crop) {	// upscale prevention
                return [
                    'width' => $width,
                    'height' => $this->getImageHeight($image, $width),
                ];
            } else {
                return [
                    'width' => $this->getImageWidth($image, $height),
                    'height' => $height,
                ];
            }
        } else {									// current has same aspect ratio as new
            return [
                'width' => $width,
                'height' => $height,
            ];
        }
    }
47058
private function _getImageToSize(array $images, int $size)
	{
		$selectedImage = null;
		$selectedSize = 0;

		foreach ($images as $image)
		{
			if (is_array($image))
			{
				$imageWidth = isset($image['width']) && is_numeric($image['width']) ? $image['width'] : 0;
				$imageHeight = isset($image['height']) && is_numeric($image['height']) ? $image['height'] : 0;
				$imageSize = max($imageWidth, $imageHeight);

				if (!$selectedImage ||
					($selectedSize < $size && $imageSize > $selectedSize) ||
					($selectedSize > $imageSize && $imageSize > $size))
				{
					$selectedImage = $image;
					$selectedSize = $imageSize;
				}
			}
		}

		return $selectedImage;
	}
1197645
function(size, callback) {
      var ratio = size.width / size.height;
      var cropPosition = {};
      var resizeWidth = width || Math.round(height * ratio);
      var resizeHeight = height || Math.round(width / ratio);

      if (crop && width && height) {
        if (ratio < width / height) {
          resizeHeight = Math.round(width / ratio);
          cropPosition = {x: 0, y: Math.round((resizeHeight - height) / 2)};
          crop = resizeHeight > height;
        } else {
          resizeWidth = Math.round(height * ratio);
          cropPosition = {x: Math.round((resizeWidth - width) / 2), y: 0};
          crop = resizeWidth > width;
        }
      }

      image
        .noProfile()
        .quality(quality)
        .resizeExact(resizeWidth, resizeHeight);

      if (crop)
        image.crop(width, height, cropPosition.x, cropPosition.y);

      image.write(thumbnailPath, callback);
    }
292322
def image(self, img):
        """"""
        if img.mode != '1':
            raise ValueError('Image must be in mode 1.')
        imwidth, imheight = img.size
        if imwidth != self.width or imheight != self.height:
            raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
                .format(self.width, self.height))
        # Grab all the pixels from the image, faster than getpixel.
        pixels = img.load()
        # Clear buffer
        for i in range(len(self.buf)):
            self.buf[i] = 0
        # Iterate through the pixels
        for x in range(self.width):       # yes this double loop is slow,
            for y in range(self.height):  #  but these displays are small!
                if pixels[(x, y)]:
                    self.pixel(x, y, 1)
521990
public static int[] shrinkImage(BufferedImage srcImg, String dest, int width, int height) throws IOException {
		int w = srcImg.getWidth(null);
		int h = srcImg.getHeight(null);

		if (w <= width && h <= height) {
			width = w;
			height = h;
		} else {
			double r1 = (double) width / (double) w;
			double r2 = (double) height / (double) h;

			if (r1 > r2) {
				width = (int) (w * r2);
				height = (int) (h * r2);
			} else {
				width = (int) (w * r1);
				height = (int) (h * r1);
			}

			if (width <= 0)
				width = 1;
			if (height <= 0)
				height = 1;
		}

		int size = resizeImage(srcImg, dest, width, height);
		return new int[] { width, height, size };
	}
984453
private int imageDataSize()
    {
		int size = 0;
    	for(int k = 0; k < imageData.length; k++) {
    		size += imageData[k].length;
    	}   
    	return size;
    }
1289048
public function getSmallestImageSet()
    {
        $imageSet = $this->getImageSet();

        $returnSize = PHP_INT_MAX;
        $returnSet = null;

        foreach ($imageSet as $set) {
            $size = $set->width * $set->height;
            if ($size < $returnSize) {
                $returnSize = $size;
                $returnSet = $set;
            }
        }

        if ($returnSet === null) {
            $returnSet = new \stdClass();
            $returnSet->slug = 'original';
        }

        return $returnSet;
    }
795007
private static int getTrimmedWidth(BufferedImage img) {
    int height = img.getHeight();
    int width = img.getWidth();
    int trimmedWidth = 0;

    for (int i = 0; i < height; i++) {
      for (int j = width - 1; j >= 0; j--) {
        if (img.getRGB(j, i) != Color.WHITE.getRGB() && j > trimmedWidth) {
          trimmedWidth = j;
          break;
        }
      }
    }

    return trimmedWidth;
  }
662896
public INDArray asRowVector(BufferedImage image) {
        if (centerCropIfNeeded) {
            image = centerCropIfNeeded(image);
        }
        image = scalingIfNeed(image, true);
        if (channels == 3) {
            return toINDArrayBGR(image).ravel();
        }
        int[][] ret = toIntArrayArray(image);
        return NDArrayUtil.toNDArray(ArrayUtil.flatten(ret));
    }
422103
def function(self,p):
        """"""
        int_index=int(len(p.generators)*wrap(0,1.0,p.index))
        pg=p.generators[int_index]

        image_array = pg(xdensity=p.xdensity,ydensity=p.ydensity,bounds=p.bounds,
                         x=p.x+p.size*(pg.x*np.cos(p.orientation)-pg.y*np.sin(p.orientation)),
                         y=p.y+p.size*(pg.x*np.sin(p.orientation)+pg.y*np.cos(p.orientation)),
                         orientation=pg.orientation+p.orientation,size=pg.size*p.size,
                         scale=pg.scale*p.scale,offset=pg.offset+p.offset)

        return image_array
1299189
function(container) {
		var top = container.el.offsetTop;
		var bottom = top+container.el.offsetHeight;
	
		var left = container.el.offsetLeft;
		var right = left+container.el.offsetWidth;
	
		return [
	    	{x : left, y: top},
	    	{x : left, y: bottom},
	    	{x : right, y: top},
	    	{x : right, y: bottom}
		];
   }