Save the image based on its file type.
@param  string $savePath     Where to save the image
@param  int    $imageQuality The output quality of the image
@return boolean
188946
public function save($savePath, $imageQuality = 95)
        {
            // If the image wasn't resized, fetch original image.
            if (!$this->imageResized) {
                $this->imageResized = $this->image;
            }

            // Get extension of the output file.
            $extension = Inflector::lower(File::extension($savePath));

            // Create and save an image based on it's extension.
            switch($extension)
            {
                case 'jpg':
                case 'jpeg':
                    if (imagetypes() & IMG_JPG) {
                        imagejpeg($this->imageResized, $savePath, $imageQuality);
                    }
                    break;

                case 'gif':
                    if (imagetypes() & IMG_GIF) {
                        imagegif($this->imageResized, $savePath);
                    }
                    break;

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

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

                    if (imagetypes() & IMG_PNG) {
                        imagepng($this->imageResized, $savePath, $invertScaleQuality);
                    }
                    break;

                default:
                    return false;
                    break;
            }

            // Remove the resource for the resized image.
            imagedestroy($this->imageResized);

            return true;
        }
597849
public function output($type = 'jpg', $quality = 75)
        {
            if($type == 'jpg' && (imagetypes() & IMG_JPG)) {
                header("Content-Type: image/jpeg");
                imagejpeg($this->im, null, $quality);
                return true;
            } elseif($type == 'png' && (imagetypes() & IMG_PNG)) {
                header("Content-Type: image/png");
                imagepng($this->im);
                return true;
            } elseif($type == 'gif' && (imagetypes() & IMG_GIF)) {
                header("Content-Type: image/gif");
                imagegif($this->im);
                return true;
            } else
                return false;
        }
650960
public function save($save_path = null, $make_paths = false)
	{
		$path = $this->source;

		if (!is_null($save_path))
		{
			$info = pathinfo($save_path);

			if ($make_paths)
			{
				\App::get('filesystem')->makeDirectory($info['dirname']);
			}

			if (!is_dir($info['dirname']) && $make_paths == false)
			{
				$this->setError(\Lang::txt('You must supply a valid path or allow save function to create recursive path'));
				return;
			}

			$path = $save_path;
		}

		$this->output($path);
	}
1350910
public function save($path)
    {

        switch ( $this->imageType ) {
            case IMAGETYPE_GIF:
                $returnData = imagegif( $this->image, $path );
                break;

            case IMAGETYPE_PNG:
                $returnData = imagepng( $this->image, $path );
                break;

            case IMAGETYPE_JPEG:
                $returnData = imagejpeg( $this->image, $path );
                break;

            case IMAGETYPE_BMP:
                $returnData = imagewbmp( $this->image, $path );
                break;

            // If the image is not one of the previous mimetype
            // We throw an exception
            default:
                throw new Exception( sprintf( 'This MimeType is not supported: %s. Image processed: %s', image_type_to_mime_type( $this->imageType ), $this->originalImagePath ) );
                break;
        }

        // Return this for chaning
        return $this;
    }
1221501
public function saveUploadFile($tempFile, $uploadPath)
    {
        $uploadPath = $this->getRealPath($uploadPath);
        if (!is_dir(dirname($uploadPath))) {
            @mkdir(dirname($uploadPath), 0755, true);
        }
        return move_uploaded_file($tempFile, $uploadPath);
    }
352749
private static void save(Bitmap src, String fileName, Bitmap.CompressFormat format, int quality) throws ImageSaveException {
        FileOutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(fileName);
            src.compress(format, quality, outputStream);
            outputStream.close();
        } catch (IOException e) {
            throw new ImageSaveException(e);
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
341212
public function saveFile($filePath, $fileMode = 'w+')
    {
        $this->saveFileOption['filePath'] = $filePath;
        $this->saveFileOption['fileMode'] = $fileMode;
        return $this;
    }
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)
882372
public function saveAsFile($diagram, $savePath) {
    if(is_dir($savePath)) {
      $filePath = $savePath.'/'.$this->cleanFileName($diagram->id).'.bpmn';
    } else {
      $filePath = './'.$this->cleanFileName($diagram->id).'.bpmn';
    }

    $handle = fopen($filePath, 'c+');
    ftruncate($handle, filesize($filePath));
    fwrite($handle, $diagram->bpmn20Xml);
    fclose($handle);

    return $filePath;
  }
1206814
private function do_resize($image, $save_path, $image_quality)
    {
        $image = $this->open_image($image);

        $this->width  = imagesx($image);
        $this->height = imagesy($image);

        // Get optimal width and height - based on $option.
        $option_array = $this->get_dimensions($this->new_width, $this->new_height, $this->option);

        $optimal_width  = $option_array['optimal_width'];
        $optimal_height = $option_array['optimal_height'];

        // Resample - create image canvas of x, y size.
        $this->image_resized = imagecreatetruecolor($optimal_width, $optimal_height);

        // Retain transparency for PNG and GIF files.
        imagecolortransparent($this->image_resized, imagecolorallocatealpha($this->image_resized, 255, 255, 255, 127));
        imagealphablending($this->image_resized, false);
        imagesavealpha($this->image_resized, true);

        // Create the new image.
        imagecopyresampled($this->image_resized, $image, 0, 0, 0, 0, $optimal_width, $optimal_height, $this->width, $this->height);

        // if option is 'crop' or 'fit', then crop too
        if ($this->option == 'crop' || $this->option == 'fit') {
            $this->crop($optimal_width, $optimal_height, $this->new_width, $this->new_height);
        }

        // Get extension of the output file
        $extension = strtolower(File::extension($save_path));

        // Create and save an image based on it's extension
        switch ($extension) {
            case 'jpg':
            case 'jpeg':
                if (imagetypes() & IMG_JPG) {
                    imagejpeg($this->image_resized, $save_path, $image_quality);
                }
                break;

            case 'gif':
                if (imagetypes() & IMG_GIF) {
                    imagegif($this->image_resized, $save_path);
                }
                break;

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

                // Invert quality setting as 0 is best, not 9
                $invert_scale_quality = 9 - $scale_quality;

                if (imagetypes() & IMG_PNG) {
                    imagepng($this->image_resized, $save_path, $invert_scale_quality);
                }
                break;

            default:
                return false;
                break;
        }

        // Remove the resource for the resized image
        imagedestroy($this->image_resized);

        return true;
    }
576174
public function save($filePath = null) {
		
		// Determine the correct file path.
		$filePath = ($filePath == null) ? $this->configFilePath : $filePath;
		
		// Store the file
		file_put_contents ( $filePath, $this->getConfigFileText () );
	}
166673
private function saveTemporaryFile($imageInstance, $sourceExtension): string
    {
        $tempPath = Craft::$app->getPath()->getRuntimePath().'imager/temp/';

        // Check if the path exists
        if (!realpath($tempPath)) {
            try {
                FileHelper::createDirectory($tempPath);
            } catch (Exception $e) {
                // just ignore for now, trying to create
            }

            if (!realpath($tempPath)) {
                $msg = Craft::t('imager', 'Temp folder “{tempPath}” does not exist and could not be created', ['tempPath' => $tempPath]);
                Craft::error($msg, __METHOD__);
                throw new ImagerException($msg);
            }
        }

        $targetFilePath = $tempPath.md5(microtime()).'.'.$sourceExtension;

        $saveOptions = [
            'jpeg_quality' => 100,
            'png_compression_level' => 1,
            'flatten' => true
        ];

        $imageInstance->save($targetFilePath, $saveOptions);

        return $targetFilePath;
    }
1367209
public function saveImage($imagePath, $saveDirPath, $separator = '-'): string
    {
        if (strpos($image = str_replace(' ', '%20', $imagePath), DIRECTORY_SEPARATOR) !== false) {
            $filename = str_replace('%20', $separator, pathinfo($image, PATHINFO_BASENAME));
            if (!empty($filename)) {
                $savePath = preg_replace(
                    '~/+~',
                    DIRECTORY_SEPARATOR,
                    implode(DIRECTORY_SEPARATOR, [$saveDirPath, $filename])
                );
                if (!file_exists($savePath)) {
                    try {
                        is_dir($saveDirPath) || mkdir($saveDirPath, 0777, true);
                        copy($image, $savePath);
                        return $savePath;
                    } catch (\Exception $e) {
                        if (strpos($_SERVER['argv'][0], 'phpunit') === false) {
                            echo 'Failed to download image, located at ' . $imagePath . ', Error: ' . $e->getMessage();
                            echo "\n";
                        }
                    }
                } else {
                    return $savePath;
                }
            }
        }
        return '';
    }
421878
protected function createThumbnail($imagePath, $thumbnailPath) {
        if ($this->config['images']['thumbnail']['enabled'] === true) {
            Log::info('generating thumbnail "' . $thumbnailPath . '"');

            // create folder if it does not exist
            if (!file_exists(dirname($thumbnailPath))) {
                mkdir(dirname($thumbnailPath), 0755, true);
            }

            $this->initUploader([
                'upload_dir' => dirname($imagePath) . '/',
            ])->create_thumbnail_image($imagePath);
        }
    }
1283475
public function save($imageLocation, $deleteFileIfExists = true)
    {
        $this->imageLocation = $this->output->getLocation() . $imageLocation;

        if (!pathinfo($this->imageLocation, PATHINFO_EXTENSION)) {
            $this->imageLocation .= '.' . $this->getImageType()->getFormat();
        }

        $data = array(
            'url'           => (string) $this->url,
            'width'         => $this->width,
            'height'        => $this->height,
            'imageLocation' => LocalPath::sanitize($this->imageLocation),
        );

        if ($this->clipWidth && $this->clipHeight) {
            $data['clipOptions']['width'] = $this->clipWidth;
            $data['clipOptions']['height'] = $this->clipHeight;
            $data['clipOptions']['top'] = $this->top;
            $data['clipOptions']['left'] = $this->left;
        }

        if ($this->backgroundColor) {
            $data['backgroundColor'] = $this->backgroundColor;
        } elseif ($this->getImageType()->getFormat() == Types\Jpg::FORMAT) {
            // If there is no background color set, and it's a jpeg
            // we need to set a bg color, otherwise the background will be black
            $data['backgroundColor'] = '#FFFFFF';
        }

        if ($this->userAgentString) {
            $data['userAgent'] = $this->userAgentString;
        }

        if ($this->timeout) {
            $data['timeout'] = $this->timeout;
        }

        if ($this->delay) {
            $data['delay'] = $this->delay;
        }

        if ($this->includedJsScripts) {
            $data['includedJsScripts'] = $this->includedJsScripts;
        }

        if ($this->includedJsSnippets) {
            $data['includedJsSnippets'] = $this->includedJsSnippets;
        }

	    if ($this->blockAnalytics) {
		    $data['blockAnalytics'] = $this->blockAnalytics;
	    }

        if ($deleteFileIfExists && file_exists($this->imageLocation) && is_writable($this->imageLocation)) {
            unlink($this->imageLocation);
        }

        if ($this->keepCookies) {
            // Take the JSON cookies and put in the array to be write in js.
            $data['cookieJar'] = $this->cookieJar->getCookiesJSON();
        }

        $jobName = md5(json_encode($data));
        $jobPath = $this->jobs->getLocation() . $jobName . '.js';

        // Saves the cookies in the same folder as the jobs.
        $cookiesPath = $this->jobs->getLocation() . $jobName . '.json';
        // Put the path in array. The js will pick up this filepath and save the cookies in it.
        $data['cookiesPath'] = LocalPath::sanitize($cookiesPath);        
        
        if (!is_file($jobPath)) {
            // Now we write the code to a js file
            $resultString = $this->getTemplateResult('screen-capture', $data);
            file_put_contents($jobPath, $resultString);
        }

        $command = sprintf("%sphantomjs %s %s", $this->binPath, $this->getOptionsString(), $jobPath);

        // Run the command and ensure it executes successfully
        $returnCode = null;
        $output = [];
        exec(sprintf("%s 2>&1", escapeshellcmd($command)), $output, $returnCode);

        if ($this->keepCookies) {
            $this->cookieJar->load($cookiesPath);
            unlink($cookiesPath);
        }

        if ($returnCode !== 0) {
            throw new PhantomJsException($output);
        }

        return file_exists($this->imageLocation);
    }
574841
public function saveToFile($filePath)
    {
        $this->adsUtilityRegistry->addUtility(
            AdsUtility::REPORT_DOWNLOADER_FILE
        );
        $this->reportDownloadResultDelegate->saveToFile($filePath);
    }
454197
protected function setSavePath($savePath): void
    {
        if (!is_dir($savePath)
            || !is_writable($savePath)
        ) {
            throw new ComponentException('Session path is not writable');
        }
        session_save_path($savePath);
    }