Save the image data to a file or file-like object
177980
def save(self, outfile):
        """"""
        if isinstance(outfile, compat.string_type):
            outfile = open(outfile, 'wb')
        outfile.write(compat.urllib2.urlopen(self.href).read())
154
def to_file(self, filename=None, write_style=True):
        
        out = zipwrap.Zippier(filename, "w")
        out.write("mimetype", self.mime_type)
        for p in self._pictures:
            out.write("Pictures/%s" % p.internal_name, p.get_data())
        out.write("content.xml", self.to_xml())
        if write_style:
            out.write("styles.xml", self.styles_xml())
        out.write("meta.xml", self.meta_xml())
        out.write("settings.xml", self.settings_xml())
        out.write("META-INF/manifest.xml", self.manifest_xml(out))
        return out
432113
def dump_image_data(dataset_dir, data_dir, dataset, color_array_info, root=None, compress=True):
    """"""
    if root is None:
        root = {}
    root['vtkClass'] = 'vtkImageData'
    container = root

    container['spacing'] = dataset.GetSpacing()
    container['origin'] = dataset.GetOrigin()
    container['extent'] = dataset.GetExtent()

    dump_all_arrays(dataset_dir, data_dir, dataset, container, compress)

    return root
798125
function storedPixelDataToImageData (image) {
  const minPixelValue = image.minPixelValue;
  let canvasImageDataIndex = 0;
  let storedPixelDataIndex = 0;
  // Only 3 channels, since we use WebGL's RGB texture format
  const numStoredPixels = image.width * image.height * 4;
  const numOutputPixels = image.width * image.height * 3;
  const storedPixelData = image.getPixelData();
  const data = new Uint8Array(numOutputPixels);

  // NOTE: As of Nov 2014, most javascript engines have lower performance when indexing negative indexes.
  // We have a special code path for this case that improves performance.  Thanks to @jpambrun for this enhancement
  if (minPixelValue < 0) {
    while (storedPixelDataIndex < numStoredPixels) {
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++] + (-minPixelValue); // Red
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++] + (-minPixelValue); // Green
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++] + (-minPixelValue); // Blue
      storedPixelDataIndex += 1; // The stored pixel data has 4 channels
    }
  } else {
    while (storedPixelDataIndex < numStoredPixels) {
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++]; // Red
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++]; // Green
      data[canvasImageDataIndex++] = storedPixelData[storedPixelDataIndex++]; // Blue
      storedPixelDataIndex += 1; // The stored pixel data has 4 channels
    }
  }

  return data;
}
298997
def _save_to(self, im, path, format=None):
        
        format = format or im.format
        if not format:
            _, format = splitext(path)
            format = format[1:]
        im.format = format.lower()
        im.save(filename=path)
1034215
def _get_display_data_with_images(data, images):
  """"""

  if not images:
    return data

  display_data = copy.deepcopy(data)
  for img_col in images:
    for d, im in zip(display_data, images[img_col]):
      if im == '':
        d[img_col + '_image'] = ''
      else:
        im = im.copy()
        im.thumbnail((128, 128), Image.ANTIALIAS)
        buf = BytesIO()
        im.save(buf, "PNG")
        content = base64.b64encode(buf.getvalue()).decode('ascii')
        d[img_col + '_image'] = content

  return display_data
11245
def save_to(self, image):
        
        if not isinstance(image, self.__class__):
            raise ConuException("Invalid target image type", type(image))
        self.copy(image.name, image.tag,
                  target_transport=image.transport, target_path=image.path,
                  logs=False)
793974
def get_img_data(f, maxsize = (1200, 850), first = False):
    
    img = Image.open(f)
    img.thumbnail(maxsize)
    if first:                     # tkinter is inactive the first time
        bio = io.BytesIO()
        img.save(bio, format = "PNG")
        del img
        return bio.getvalue()
    return ImageTk.PhotoImage(img)
634734
def save(self, delete_zip_import=True, *args, **kwargs):
        
        super(BaseGallery, self).save(*args, **kwargs)
        if self.zip_import:
            zip_file = ZipFile(self.zip_import)
            for name in zip_file.namelist():
                data = zip_file.read(name)
                try:
                    from PIL import Image
                    image = Image.open(BytesIO(data))
                    image.load()
                    image = Image.open(BytesIO(data))
                    image.verify()
                except ImportError:
                    pass
                except:
                    continue
                name = os.path.split(name)[1]

                # In python3, name is a string. Convert it to bytes.
                if not isinstance(name, bytes):
                    try:
                        name = name.encode('cp437')
                    except UnicodeEncodeError:
                        # File name includes characters that aren't in cp437,
                        # which isn't supported by most zip tooling. They will
                        # not appear correctly.
                        tempname = name

                # Decode byte-name.
                if isinstance(name, bytes):
                    encoding = charsetdetect(name)['encoding']
                    tempname = name.decode(encoding)

                # A gallery with a slug of "/" tries to extract files
                # to / on disk; see os.path.join docs.
                slug = self.slug if self.slug != "/" else ""
                path = os.path.join(GALLERIES_UPLOAD_DIR, slug, tempname)
                try:
                    saved_path = default_storage.save(path, ContentFile(data))
                except UnicodeEncodeError:
                    from warnings import warn
                    warn("A file was saved that contains unicode "
                         "characters in its path, but somehow the current "
                         "locale does not support utf-8. You may need to set "
                         "'LC_ALL' to a correct value, eg: 'en_US.UTF-8'.")
                    # The native() call is needed here around str because
                    # os.path.join() in Python 2.x (in posixpath.py)
                    # mixes byte-strings with unicode strings without
                    # explicit conversion, which raises a TypeError as it
                    # would on Python 3.
                    path = os.path.join(GALLERIES_UPLOAD_DIR, slug,
                                        native(str(name, errors="ignore")))
                    saved_path = default_storage.save(path, ContentFile(data))
                self.images.create(file=saved_path)
            if delete_zip_import:
                zip_file.close()
                self.zip_import.delete(save=True)
1049224
def save_object(fname, obj):
    """"""

    fd = gzip.open(fname, "wb")
    six.moves.cPickle.dump(obj, fd)
    fd.close()
493386
def _save_image(image, filename, return_img=None):
        """"""
        if not image.size:
            raise Exception('Empty image.  Have you run plot() first?')

        # write screenshot to file
        if isinstance(filename, str):
            if isinstance(vtki.FIGURE_PATH, str) and not os.path.isabs(filename):
                filename = os.path.join(vtki.FIGURE_PATH, filename)
            if not return_img:
                return imageio.imwrite(filename, image)
            imageio.imwrite(filename, image)

        return image
1003365
def save(filename)
      assert_exists
      image_reader = @object.getImageReader
      file = java.io.File.new(filename)
      buffered_image = image_reader.read(0);
      javax.imageio.ImageIO.write(buffered_image, image_reader.getFormatName(), file);
    end
567297
def write_object_to_file(self, obj, path='.', filename=None):
        """"""
        output = self.json_dumps(obj) + '\n'
        if filename is None:
            filename = self.safe_filename(obj['_type'], obj['_id'])
        filename = os.path.join(path, filename)
        self.pr_inf("Writing to file: " + filename)
        with open(filename, 'w') as f:
            f.write(output)
        # self.pr_dbg("Contents: " + output)
        return filename
581089
def save_data(self, filename):
        
        with zopen(filename, "wt") as f:
            json.dump(list(self._data), f, cls=MontyEncoder)
1224561
def process_image(self, decorator):
        
        savefig_dir = self.savefig_dir
        source_dir = self.source_dir
        saveargs = decorator.split(' ')
        filename = saveargs[1]
        # insert relative path to image file in source
        outfile = os.path.relpath(os.path.join(savefig_dir,filename),
                    source_dir)

        imagerows = ['.. image:: %s'%outfile]

        for kwarg in saveargs[2:]:
            arg, val = kwarg.split('=')
            arg = arg.strip()
            val = val.strip()
            imagerows.append('   :%s: %s'%(arg, val))

        image_file = os.path.basename(outfile) # only return file name
        image_directive = '\n'.join(imagerows)
        return image_file, image_directive
545724
def load_and_save_image(url, destination):
    """"""
    from urllib2 import Request, urlopen, URLError, HTTPError
    # create the url and the request
    req = Request(url)

    # Open the url
    try:
        f = urlopen(req)
        print "downloading " + url

        # Open our local file for writing

        local_file = open(destination, "wb")
        # Write to our local file
        local_file.write(f.read())
        local_file.close()

        file_type = imghdr.what(destination)
        local_file = open(destination, "rb")
        data = local_file.read()
        local_file.close()

        final_file = open(destination + '.' + file_type, "wb")
        final_file.write(data)
        final_file.close()
        print('save image preview {0}'.format(destination + '.' + file_type))
        os.remove(destination)

    # handle errors
    except HTTPError, e:
        print "HTTP Error:", e.code, url
    except URLError, e:
        print "URL Error:", e.reason, url
204437
def pil_save(self, filename, fformat=None, fill_value=None,
                 compute=True, **format_kwargs):
        
        fformat = fformat or os.path.splitext(filename)[1][1:4]
        fformat = check_image_format(fformat)

        if fformat == 'png':
            # Take care of GeoImage.tags (if any).
            format_kwargs['pnginfo'] = self._pngmeta()

        img = self.pil_image(fill_value, compute=False)
        delay = img.save(filename, fformat, **format_kwargs)
        if compute:
            return delay.compute()
        return delay