Saving image in jpeg to file with better quality 90

@param src      source image
@param fileName destination file name
@throws ImageSaveException if it is unable to save image
511852
public static void saveHq(Bitmap src, String fileName) throws ImageSaveException {
        saveJpeg(src, fileName, JPEG_QUALITY_HQ);
    }
877814
private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed
		final File dir = lastSaveDirectory();
		final JFileChooser chooser = dir != null
			? new JFileChooser(dir)
			: new JFileChooser();
		chooser.setDialogTitle("Save Polygon Image");
		chooser.setDialogType(JFileChooser.SAVE_DIALOG);
		chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
		chooser.setMultiSelectionEnabled(false);
		chooser.addChoosableFileFilter(new FileNameExtensionFilter(
			"Images (*.png)",
			ImageIO.getReaderFileSuffixes()
		));

		final int returnVal = chooser.showSaveDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			final String name = chooser.getSelectedFile().getAbsolutePath();
			final File imageFile = name.toLowerCase().endsWith(".png")
				? new File(name)
				: new File(name + ".png");

			try {
				final Dimension dim = _polygonPanel.getDimension();
				final PolygonChromosome ch = _polygonPanel.getChromosome();
				writeImage(imageFile, ch, dim.width, dim.height);

				if (imageFile.getParentFile() != null) {
					lastSaveDirectory(imageFile.getParentFile());
				}
			} catch (Exception e) {
				JOptionPane.showMessageDialog(
					rootPane,
					format("Error while saving image '%s'.", imageFile),
					e.toString(),
					JOptionPane.ERROR_MESSAGE
				);
			}
		}
    }
1367658
def write(self, filename=None):
        """"""
        if filename is None:
            filename = self._filename

        exif_bytes = piexif.dump(self._ef)

        with open(self._filename, "rb") as fin:
            img = fin.read()
        try:
            piexif.insert(exif_bytes, img, filename)

        except IOError:
            type, value, traceback = sys.exc_info()
            print >> sys.stderr, "Error saving file:", value
799061
protected void snapshot(String fileName) throws Exception {
	    configuration.save(new File(fileName));
        model.snapshotSessionDb(this.fileName, fileName);
	}
1337294
public void save(Path filename, boolean pretty) throws IOException {
        if (filename == null || Files.exists(filename)) {
            throw new IOException("File path not correct, either it is null or file already exists: " + filename);
        }

        String text;
        if (pretty) {
            text = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(variantMetadata);
        } else {
            text = mapper.writeValueAsString(variantMetadata);
        }

        PrintWriter writer = new PrintWriter(new FileOutputStream(filename.toFile()));
        writer.write(text);
        writer.close();
    }
1164649
public static void saveImage(BufferedImage image, OutputStream output) throws IOException
    {
        ImageIO.write(image, "png", output);
    }
404856
public static void saveLq(Bitmap src, String fileName) throws ImageSaveException {
        saveJpeg(src, fileName, JPEG_QUALITY_LOW);
    }
1310690
public function save($saveName, $quality = 80)
    {
        $type         = $this->getType(pathinfo($saveName, PATHINFO_EXTENSION));
        $imageFunc    = 'image' . $type;
        $errorMessage = 'Image saved is failed! Check the directory is can write?';

        if ($type === 'jpeg')
        {
            imageinterlace($this->newImage, true);

            if ( !$imageFunc($this->newImage, $saveName, $quality) )
            {
                throw new \ErrorException($errorMessage);
            }
        }
        else
        {
            if (!$imageFunc($this->newImage, $saveName))
            {
                throw new \ErrorException($errorMessage);
            }
        }

        $this->destroyAll();

        return $this;
    }
27006
public function save($filename, $image_type = null, $quality = null, $permissions = null)
    {
        $image_type = $image_type ?: $this->source_type;
        if ($this->centered) {
            $dest_image = imagecreatetruecolor($this->ask_w, $this->ask_h);
        } else {
            $dest_image = imagecreatetruecolor($this->getDestWidth(), $this->getDestHeight());
        }
        imageinterlace($dest_image, $this->interlace);
        switch ($image_type) {
            case IMAGETYPE_GIF:
                $background = imagecolorallocatealpha($dest_image, 255, 255, 255, 1);
                imagecolortransparent($dest_image, $background);
                imagefill($dest_image, 0, 0, $background);
                imagesavealpha($dest_image, true);
                break;
            case IMAGETYPE_JPEG:
                $background = imagecolorallocate($dest_image, 255, 255, 255);
                if ($this->centered) {
                    imagefilledrectangle($dest_image, 0, 0, $this->ask_w, $this->ask_h, $background);
                } else {
                    imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background);
                }
                break;
            case IMAGETYPE_PNG:
                imagealphablending($dest_image, false);
                $background = imagecolorallocate($dest_image, 255, 255, 255);
                if ($this->centered) {
                    imagefilledrectangle($dest_image, 0, 0, $this->ask_w, $this->ask_h, $background);
                } else {
                    imagefilledrectangle($dest_image, 0, 0, $this->getDestWidth(), $this->getDestHeight(), $background);
                }
                    imagesavealpha($dest_image, true);
                break;
        }
        imagecopyresampled(
            $dest_image,
            $this->source_image,
            $this->dest_x,
            $this->dest_y,
            $this->source_x,
            $this->source_y,
            $this->getDestWidth(),
            $this->getDestHeight(),
            $this->source_w,
            $this->source_h
        );
        switch ($image_type) {
            case IMAGETYPE_GIF:
                imagegif($dest_image, $filename);
                break;
            case IMAGETYPE_JPEG:
                if ($quality === null) {
                    $quality = $this->quality_jpg;
                }
                imagejpeg($dest_image, $filename, $quality);
                break;
            case IMAGETYPE_PNG:
                if ($quality === null) {
                    $quality = $this->quality_png;
                }
                imagepng($dest_image, $filename, $quality);
                break;
        }
        if ($permissions) {
            chmod($filename, $permissions);
        }
        return $this;
    }
63011
public function saveImage($savePath, $imageQuality = "100")
		# Author:     Jarrod Oberto
		# Date:       27-02-08
		# Purpose:    Saves the image
		# Param in:   $savePath: Where to save the image including filename:
		#             $imageQuality: image quality you want the image saved at 0-100
		# Param out:  n/a
		# Reference:
		# Notes:    * gif doesn't have a quality parameter
		#       * jpg has a quality setting 0-100 (100 being the best)
		#       * png has a quality setting 0-9 (0 being the best)
		#
		#             * bmp files have no native support for bmp files. We use a
		#       third party class to save as bmp.
	{

		// *** Perform a check or two.
		if ( ! is_resource($this->imageResized))
		{
			if ($this->debug)
			{
				throw new Exception('saveImage: This is not a resource.');
			}
			else
			{
				throw new Exception();
			}
		}
		$fileInfoArray = pathInfo($savePath);
		clearstatcache();
		if ( ! is_writable($fileInfoArray['dirname']))
		{
			if ($this->debug)
			{
				throw new Exception('The path is not writable. Please check your permissions.');
			}
			else
			{
				throw new Exception();
			}
		}

		// *** Get extension
		$extension = strrchr($savePath, '.');
		$extension = fix_strtolower($extension);

		$error = '';

		switch ($extension)
		{
			case '.jpg':
			case '.jpeg':
				$this->checkInterlaceImage($this->isInterlace);
				if (imagetypes() & IMG_JPG)
				{
					imagejpeg($this->imageResized, $savePath, $imageQuality);
				}
				else
				{
					$error = 'jpg';
				}
				break;

			case '.gif':
				$this->checkInterlaceImage($this->isInterlace);
				if (imagetypes() & IMG_GIF)
				{
					imagegif($this->imageResized, $savePath);
				}
				else
				{
					$error = 'gif';
				}
				break;

			case '.png':
				// *** Scale quality from 0-100 to 0-9
				$scaleQuality = round(($imageQuality / 100) * 9);

				// *** Invert qualit setting as 0 is best, not 9
				$invertScaleQuality = 9 - $scaleQuality;

				$this->checkInterlaceImage($this->isInterlace);
				if (imagetypes() & IMG_PNG)
				{
					imagepng($this->imageResized, $savePath, $invertScaleQuality);
				}
				else
				{
					$error = 'png';
				}
				break;

			case '.bmp':
				file_put_contents($savePath, $this->GD2BMPstring($this->imageResized));
				break;


			// ... etc

			default:
				// *** No extension - No save.
				$this->errorArray[] = 'This file type (' . $extension . ') is not supported. File not saved.';
				break;
		}

		//imagedestroy($this->imageResized);

		// *** Display error if a file type is not supported.
		if ($error != '')
		{
			$this->errorArray[] = $error . ' support is NOT enabled. File not saved.';
		}
	}
134132
public function save( $fileName, $type = IMAGETYPE_PNG, $quality = 100 )
	{
		$this->saveImage( $fileName, $this->resource, $type, $quality );
	}
323214
@CommandArgument
  public void save(
      @OptionArgument("filename") String filename) {

    try {
      PrintStream out = new PrintStream(new FileOutputStream(filename));

      for (User user : users.values()) {
        out.println(user);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

  }
1273337
@GwtIncompatible("com.google.io.Files")
  public void save(String filename) throws IOException {
    Files.write(toBytes(), new File(filename));
  }
1221931
public static byte[] saveHq(Bitmap src) throws ImageSaveException {
        return save(src, Bitmap.CompressFormat.JPEG, JPEG_QUALITY_HQ);
    }
623671
public function save($filename)
    {
        $type = pathinfo($filename, PATHINFO_EXTENSION);
        $type = ($type === 'jpg') ? 'jpeg' : $type;
        $type = (in_array($type, $this->imageTypes)) ? $type : 'png';

        header('Content-type: image/' . $type);

        $imageFunc = 'image' . $type;
        $imageFunc($this->image, $filename);

        $this->destroy($this->image);

        return $this;
    }
1048546
public void saveImages( Element form )
                            throws IOException {
        List<Element> images = DomUtils.getElementsByTagName( form, "img" );
        int imageCount = 1;
        for ( Element image : images ) {
            if ( image.hasAttribute( "src" ) ) {
                String src = image.getAttribute( "src" );
                String imageFormat = parseImageFormat( src );
                String testName = System.getProperty( "TestName" );
                String imgName = parseImageName( testName );
                URL url = new URL( src );
                BufferedImage img = ImageIO.read( url );
                File file = createImageFile( imageCount, imageFormat, imgName );
                if ( !file.exists() ) {
                    file.getParentFile().mkdirs();
                }
                ImageIO.write( img, imageFormat, file );
                imageCount++;
            }
        }
    }
1000388
public File save(final String filename, final Serializer serializer) {
        File file = serializer.save(this, filename);
        if (log != null) //noinspection ConstantConditions
            log.info("Reflections successfully saved in " + file.getAbsolutePath() + " using " + serializer.getClass().getSimpleName());
        return file;
    }