Sets the format used for rendering to the HTML5 canvas.
        'png' offers greater clarity, especially for small text, but
        does not have as good of performance as 'jpeg'.
960844
def set_html5_canvas_format(self, fmt):
        
        fmt = fmt.lower()
        if fmt not in ('jpeg', 'png'):
            raise ValueError("Format must be one of {jpeg|png} not '%s'" % (
                fmt))

        settings = self.get_settings()
        settings.set(html5_canvas_format=fmt)
200726
function (src, data, cb) {
    var texture;
    texture = new THREE.CanvasTexture(src);
    setTextureProperties(texture, data);
    cb(texture);
  }
411793
function(){
    this.width = this.container.width();
    this.height = this.container.height();
    this.resize();
    this.canvas.setSize(this.width, this.height);
    this.applyTransform();
  }
700114
def setFormatMetadata(self, format):
    
    assert((self.needMetadataUpdate(CoverImageMetadata.FORMAT)) or
           (self.format is format))
    self.format = format
    self.check_metadata &= ~CoverImageMetadata.FORMAT
664128
def render_to_png(self, filename=None, dpi=72, **kwargs):
        """"""
        import cairosvg
        return cairosvg.svg2png(
            bytestring=self.render(**kwargs), write_to=filename, dpi=dpi
        )
1252427
def format_image(self, image, image_format, **kwargs):
        """"""

        if image_format in ('png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp'):
            if image_format != 'webp' and FORCE_WEBP:
                # Always return WebP when supported by the browser
                accept = self.request.META['HTTP_ACCEPT'].split(',')
                if 'image/webp' in accept:
                    image = image.convert('RGBA')
                    image_format = 'webp'
                    kwargs = {'lossless': True}

            if image_format == 'png':
                kwargs['optimize'] = True
            elif image_format == 'jpg':
                image.convert('RGB')
                kwargs['progressive'] = True

            buffer = six.BytesIO()
            image.save(buffer, image_format, **kwargs)
            return buffer.getvalue(), "image/{}".format(image_format)
        else:
            raise ValueError('Unsupported format: {}'.format(image_format))
897242
function setCanvasSize (width, height) {
            canvas.setAttribute('width', width);
            canvas.setAttribute('height', height);
            canvas.style.width = width + 'px';
            canvas.style.height = height + 'px';
        }
756681
def set_format *args
      global, format = args.fetch_opts [nil], :type => :console, :time => ["%H:%M:%S", "%03d"]                  
      format = if format[:type] == :html; {
                    :caller => "<a class='l'>%f:%l</a> <a class='m'>:%m</a>", 
                    :format => "<div class='line'><a class='t'>%time</a> <a class='%mode'>%mode</m> [%caller]: <p>%text</p>%att</div>",
                    :att =>"<div class='att'><div class='hide'>+</div><pre>%s</pre></div>",
                    :serializer => RMTools::RMLogger::HTML
                  }; else {
                    :caller => "#{@c.gray('%f:%l')} #{@c.red_bold(':%m')}", 
                    :format => "%time %mode [%caller]: %text"
                  } end.merge format
      if global
        _set_format @default_format, format
      else
        _set_format(file_format={}, format)
        @file_formats[File.expand_path(caller[0].till ':')] = file_format
      end
    end
1100089
def save_as_png(self, filename, width=300, height=250, render_time=1):
        """"""
        self.driver.set_window_size(width, height)
        self.driver.get('file://{path}/{filename}'.format(
            path=os.getcwd(), filename=filename + ".html"))
        time.sleep(render_time)
        self.driver.save_screenshot(filename + ".png")
801344
def set_input_format(self, content_type, handler):
        """"""
        if getattr(self, '_input_format', None) is None:
            self._input_format = {}
        self._input_format[content_type] = handler
267329
def format_image(self, image, image_format, **kwargs):
        """"""

        image_format = image_format.lower()
        accept = self.request.META['HTTP_ACCEPT'].split(',')

        if FORCE_WEBP and 'image/webp' in accept:
            image_format = 'webp'
        elif image_format == 'png8':
            alpha = image.split()[-1]
            image = image.convert('RGB')
            image = image.convert('P', palette=Image.ADAPTIVE, colors=255)
            image.paste(255, Image.eval(alpha, lambda x: 255 if x <= 128 else 0))
            image_format = 'png'
            kwargs['transparency'] = 255
        elif image_format in ('png32', 'png24'):
            image_format = 'png'

        return super(GetImageView, self).format_image(image, image_format, **kwargs)
1216955
function shrinkImage(base64Image, targetSize) {

  return new Promise( (resolve, reject) => {

    let canvas  = document.createElement('canvas');
    let image   = new Image();

    image.onload = _ => {

      canvas.height = image.naturalHeight;
      canvas.width  = image.naturalWidth;

      canvas.getContext('2d').drawImage(image, 0, 0);

      return resolve(shrink(95));

      function shrink(quality) {
        let redrawnImage = canvas.toDataURL('image/jpeg', quality/100);

        // 1. Stop at zero because quality can't get any worse!
        // 2. Base64 encoded images are 1.33 times larger than once they are converted back to a blob.
        return quality !== 0 && redrawnImage.length / 1.33 > targetSize ? shrink(quality - 5) : redrawnImage;
      }

    };

    image.src = base64Image;

  });
}
1181528
def png(file, box, paint, trans)
      Squib.logger.debug {"RENDERING PNG: \n  file: #{file}\n  box: #{box}\n  paint: #{paint}\n  trans: #{trans}"}
      return if file.nil? or file.eql? ''
      png = Squib.cache_load_image(file)
      use_cairo do |cc|
        cc.translate(box.x, box.y)
        box.width    = png.width.to_f  if box.width  == :native
        box.height   = png.height.to_f if box.height == :native
        box.width    = png.width.to_f * box.height.to_f / png.height.to_f if box.width == :scale
        box.height   = png.height.to_f * box.width.to_f / png.width.to_f  if box.height == :scale

        scale_width  = box.width.to_f / png.width.to_f
        scale_height = box.height.to_f / png.height.to_f
        warn_png_scale(file, scale_width, scale_height)
        cc.scale(scale_width, scale_height)

        cc.rotate(trans.angle)
        cc.flip(trans.flip_vertical, trans.flip_horizontal, box.width / 2, box.height / 2)
        cc.translate(-box.x, -box.y)

        trans.crop_width  = png.width.to_f  if trans.crop_width  == :native
        trans.crop_height = png.height.to_f if trans.crop_height == :native
        cc.rounded_rectangle(box.x, box.y, trans.crop_width, trans.crop_height, trans.crop_corner_x_radius, trans.crop_corner_y_radius)
        cc.clip
        cc.translate(-trans.crop_x, -trans.crop_y)


        cc.set_source(png, box.x, box.y)
        cc.operator = paint.blend unless paint.blend == :none
        if paint.mask.empty?
          cc.paint(paint.alpha)
        else
          cc.set_source_squibcolor(paint.mask)
          cc.mask(png, box.x, box.y)
        end
      end
    end
140481
public void setPixelSize(int width, int height) {
		layerHtmlContainer.setPixelSize(width, height);
		drawingArea.setWidth(width);
		drawingArea.setHeight(height);
		canvasPanel.setPixelSize(width, height);
		for (CanvasContainer container : worldCanvases) {
			container.setPixelSize(width, height);
		}
		super.setPixelSize(width, height);
	}
209209
function (format, quality) {
      var canvasEl = this.upperCanvasEl || this.lowerCanvasEl;

      this.renderAll(true);
      var data = (fabric.StaticCanvas.supports('toDataURLWithQuality'))
                   ? canvasEl.toDataURL('image/' + format, quality)
                   : canvasEl.toDataURL('image/' + format);
      this.renderAll();
      return data;
    }
555398
def encode_images_as_png(images):
  """"""
  if tf.executing_eagerly():
    for image in images:
      yield tf.image.encode_png(image).numpy()
  else:
    (height, width, channels) = images[0].shape
    with tf.Graph().as_default():
      image_t = tf.placeholder(dtype=tf.uint8, shape=(height, width, channels))
      encoded_image_t = tf.image.encode_png(image_t)
      with tf.Session() as sess:
        for image in images:
          enc_string = sess.run(encoded_image_t, feed_dict={image_t: image})
          yield enc_string
458628
def parse_render(render):
    
    formats = {
        'jpeg': guess_all_extensions('image/jpeg'),
        'png': guess_all_extensions('image/png'),
        'gif': guess_all_extensions('image/gif'),
        'bmp': guess_all_extensions('image/x-ms-bmp'),
        'tiff': guess_all_extensions('image/tiff'),
        'xbm': guess_all_extensions('image/x-xbitmap'),
        'pdf': guess_all_extensions('application/pdf')
    }
    if not render:
        render = 'png'
    else:
        render = render.lower()
        for k, v in formats.items():
            if '.%s' % render in v:
                render = k
                break
        else:
            render = 'png'
    return render