Used for generating thumbnails.  Does not include overlaid
        graphics.
8063
def save_plain_image_as_file(self, filepath, format='png', quality=90):
        
        qimg = self.get_plain_image_as_widget()
        qimg.save(filepath, format=format, quality=quality)
288163
def _thumbnail_div(target_dir, src_dir, fname, snippet, is_backref=False,
                   check=True):
    """"""
    thumb, _ = _find_image_ext(
        os.path.join(target_dir, 'images', 'thumb',
                     'sphx_glr_%s_thumb.png' % fname[:-3]))
    if check and not os.path.isfile(thumb):
        # This means we have done something wrong in creating our thumbnail!
        raise RuntimeError('Could not find internal sphinx-gallery thumbnail '
                           'file:\n%s' % (thumb,))
    thumb = os.path.relpath(thumb, src_dir)
    full_dir = os.path.relpath(target_dir, src_dir)

    # Inside rst files forward slash defines paths
    thumb = thumb.replace(os.sep, "/")

    ref_name = os.path.join(full_dir, fname).replace(os.path.sep, '_')

    template = BACKREF_THUMBNAIL_TEMPLATE if is_backref else THUMBNAIL_TEMPLATE
    return template.format(snippet=escape(snippet),
                           thumbnail=thumb, ref_name=ref_name)
899726
def generate_thumb(self, image):
        
        image_file = image.file
        picture = Image.open(image_file).convert('RGB')
        picture.thumbnail((10, 10))
        picture.filter(ImageFilter.GaussianBlur(radius=4))
        absolute_path = self.build_thumb_path(image)
        self.save_thumb(picture, absolute_path)
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
381206
public java.awt.Image createAwtImage(Color foreground, Color background) {
        int f = foreground.getRGB();
        int g = background.getRGB();
        Canvas canvas = new Canvas();

        paintCode();
        int h = (int)yHeight;
        int pix[] = new int[bitColumns * codeRows * h];
        int stride = (bitColumns + 7) / 8;
        int ptr = 0;
        for (int k = 0; k < codeRows; ++k) {
            int p = k * stride;
            for (int j = 0; j < bitColumns; ++j) {
                int b = outBits[p + (j / 8)] & 0xff;
                b <<= j % 8;
                pix[ptr++] = (b & 0x80) == 0 ? g : f;
            }
            for (int j = 1; j < h; ++j) {
                System.arraycopy(pix, ptr - bitColumns, pix, ptr + bitColumns * (j - 1), bitColumns);
            }
            ptr += bitColumns * (h - 1);
        }
        
        java.awt.Image img = canvas.createImage(new MemoryImageSource(bitColumns, codeRows * h, pix, 0, bitColumns));
        return img;
    }
364676
public void createImages() {
		image = UtilImageIO.loadImage(UtilIO.pathExample("standard/barbara.jpg"));

		gray = ConvertBufferedImage.convertFromSingle(image, null, GrayU8.class);
		derivX = GeneralizedImageOps.createSingleBand(GrayS16.class, gray.getWidth(), gray.getHeight());
		derivY = GeneralizedImageOps.createSingleBand(GrayS16.class, gray.getWidth(), gray.getHeight());

		GImageDerivativeOps.gradient(DerivativeType.SOBEL, gray, derivX, derivY, BorderType.EXTENDED);
	}
672251
def thumbnail!
      begin
        image = MiniMagick::Image.open(@file.path)
        image.resize("#{Pushfile.settings[:images][:thumb][:width]}x")
      rescue
        @thumb = nil
      else
        t = @name.split('.'); ext = t.pop
        @thumb = t.join(".").concat("_thumb.#{ext}")
        image.write("/tmp/#{@thumb}") rescue @thumb = nil
      end
    end
259924
def convert_thumbnail_to_pil(thumbnail, mode='RGB'):
    """"""
    from PIL import Image
    if thumbnail.fmt == 0:
        size = (thumbnail.width, thumbnail.height)
        stride = thumbnail.widthbytes
        return Image.frombytes('RGBX', size, thumbnail.data, 'raw', mode,
                                stride)
    elif thumbnail.fmt == 1:
        return Image.open(io.BytesIO(thumbnail.data))
    else:
        raise ValueError('Unknown thumbnail format %d' % (thumbnail.fmt))
34315
private Graphics2D initGraphics(BufferedImage img)
	{
		Graphics2D g = img.createGraphics();
		g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
		g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
		if (options.antialias)
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

		g.setFont(font);

		if (options.debug)
		{
			int color = 0x666666;
			for (int i = 0; i < img.getWidth(); i += 25)
			{
				if (i % 500 == 0)
					color = 0x333333;
				else if (i % 100 == 0)
					color = 0x777777;
				else
					color = 0xBBBBBB;
				g.setColor(new Color(color));
				g.drawLine(i, 0, i, img.getWidth());
				g.drawLine(0, i, img.getHeight(), i);
			}
		}

		g.setColor(options.debug ? Color.BLACK : Color.WHITE);

		return g;
	}
175014
public static byte[] getPixelsBGR(BufferedImage img, int y, int w, byte[] array, int[] temp) {
    final int x = 0;
    final int h = 1;

    assert array.length == temp.length * nrChannels(img);
    assert (temp.length == w);

    int imageType = img.getType();
    Raster raster;
    switch (imageType) {
      case BufferedImage.TYPE_3BYTE_BGR:
      case BufferedImage.TYPE_4BYTE_ABGR:
      case BufferedImage.TYPE_4BYTE_ABGR_PRE:
      case BufferedImage.TYPE_BYTE_GRAY:
        raster = img.getRaster();
        //int ttype= raster.getTransferType();
        raster.getDataElements(x, y, w, h, array);
        break;
      case BufferedImage.TYPE_INT_BGR:
        raster = img.getRaster();
        raster.getDataElements(x, y, w, h, temp);
        ints2bytes(temp, array, 0, 1, 2);  // bgr -->  bgr
        break;
      case BufferedImage.TYPE_INT_RGB:
        raster = img.getRaster();
        raster.getDataElements(x, y, w, h, temp);
        ints2bytes(temp, array, 2, 1, 0);  // rgb -->  bgr
        break;
      case BufferedImage.TYPE_INT_ARGB:
      case BufferedImage.TYPE_INT_ARGB_PRE:
        raster = img.getRaster();
        raster.getDataElements(x, y, w, h, temp);
        ints2bytes(temp, array, 2, 1, 0, 3);  // argb -->  abgr
        break;
      case BufferedImage.TYPE_CUSTOM: // TODO: works for my icon image loader, but else ???
        img.getRGB(x, y, w, h, temp, 0, w);
        ints2bytes(temp, array, 2, 1, 0, 3);  // argb -->  abgr
        break;
      default:
        img.getRGB(x, y, w, h, temp, 0, w);
        ints2bytes(temp, array, 2, 1, 0);  // rgb -->  bgr
        break;
    }

    return array;
  }
1008642
private ByteArrayInputStream generateThumbImageStream(InputStream inputStream,
                                                          ThumbImage thumbImage) throws IOException {
        //根据传入配置生成缩略图
        if (thumbImage.isDefaultConfig()) {
            //在中间修改配置，这里不是一个很好的实践，如果有时间再进行优化
            thumbImage.setDefaultSize(thumbImageConfig.getWidth(), thumbImageConfig.getHeight());
            return generateThumbImageByDefault(inputStream);
        } else if (thumbImage.getPercent() != 0) {
            return generateThumbImageByPercent(inputStream, thumbImage);
        } else {
            return generateThumbImageBySize(inputStream, thumbImage);
        }

    }
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);
    }
737875
def thumbnail(parser, token):
    '''
    
    '''

    thumb = None

    if SORL:
        try:
            thumb = sorl_thumb(parser, token)
        except Exception:
            thumb = False

    if EASY and not thumb:
        thumb = easy_thumb(parser, token)

    return thumb
716679
RenderedImage createSimpleIndexImage() {
        ColorModel srcCM = src.getColorModel();
        if(srcCM instanceof IndexColorModel) {
            return src;
        }
        
        Raster srcRaster = src.getData();
        boolean hasTransparent = srcCM.getTransparency() != Transparency.OPAQUE;
        int maxColorCount = 256;
        if(hasTransparent) {
            maxColorCount = 255;
        }
        
        int num = 0;
        Set<Integer> colorSet = new HashSet<Integer>();
        int[] colorArrays = new int[maxColorCount];
        for(int x = 0; x < src.getWidth(); x++) {
            for(int y = 0; y < src.getHeight(); y++) {
                int rgb = srcCM.getRGB(srcRaster.getDataElements(x, y, null)) & 0xFFFFFF;
                if(!colorSet.contains(rgb)) {
                    if(num == maxColorCount) {
                        return null;
                    }
                    
                    colorArrays[num++] = rgb;
                    colorSet.add(rgb);
                }
            }
        }
        if(num == 0) {
            throw new IllegalStateException("This image has no color");
        }
        
        int[] colors = null;
        if(hasTransparent) {
            colors = new int[num + 1];
            System.arraycopy(colorArrays, 0, colors, 1, num);
            colors[0] = 0;
        } else {
            colors = new int[num];
            System.arraycopy(colorArrays, 0, colors, 0, num);
        }
        
        Arrays.sort(colors);
        
        byte[] red = new byte[colors.length];
        byte[] green = new byte[colors.length];
        byte[] blue = new byte[colors.length];
        for(int i = 0; i < colors.length; i++) {
            red[i] = (byte)((colors[i] >> 16) & 0xFF);
            green[i] = (byte)((colors[i] >> 8) & 0xFF);
            blue[i] = (byte)((colors[i]) & 0xFF);
        }

        IndexColorModel destCM = null;
        if(hasTransparent) {
            destCM = new IndexColorModel(8, colors.length, red, green, blue, 0);
        } else {
            destCM = new IndexColorModel(8, colors.length, red, green, blue);
        }
        
        BufferedImage image = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED, destCM);
        WritableRaster raster = image.getRaster();
        for (int x = 0; x < src.getWidth(); x++) {
            for (int y = 0; y < src.getHeight(); y++) {
                int argb = srcCM.getRGB(srcRaster.getDataElements(x, y, null));
                if(hasTransparent && ((argb & 0xFF000000) != 0xFF000000)) {
                    raster.setSample(x, y, 0, 0);
                } else {
                    int index = Arrays.binarySearch(colors, (argb & 0x00FFFFFF));
                    if(index < 0) {
                        throw new IllegalStateException("Some colors not indexed");
                    }
                    raster.setSample(x, y, 0, index);
                }
            }
        }

        return image;
    }
459288
private void generatePatternBitmap() {
    if (getBounds().width() <= 0 || getBounds().height() <= 0) {
      return;
    }

    bitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);

    Rect r = new Rect();
    boolean verticalStartWhite = true;
    for (int i = 0; i <= numRectanglesVertical; i++) {
      boolean isWhite = verticalStartWhite;
      for (int j = 0; j <= numRectanglesHorizontal; j++) {
        r.top = i * rectangleSize;
        r.left = j * rectangleSize;
        r.bottom = r.top + rectangleSize;
        r.right = r.left + rectangleSize;
        canvas.drawRect(r, isWhite ? paintWhite : paintGray);
        isWhite = !isWhite;
      }
      verticalStartWhite = !verticalStartWhite;
    }
  }
747194
def downloadThumbnail(self, outPath):
        """"""
        url = self._url + "/info/thumbnail"
        params = {

        }
        return self._get(url=url,
                            out_folder=outPath,
                            file_name=None,
                            param_dict=params,
                            securityHandler=self._securityHandler,
                            proxy_url=self._proxy_url,
                            proxy_port=self._proxy_port)
1193952
def write(self, image, options, thumbnail):
        
        format_ = options['format']
        quality = options['quality']
        image_info = options.get('image_info', {})
        # additional non-default-value options:
        progressive = options.get('progressive', settings.THUMBNAIL_PROGRESSIVE)
        raw_data = self._get_raw_data(
            image, format_, quality,
            image_info=image_info,
            progressive=progressive
        )
        thumbnail.write(raw_data)