save

Save the image to an image format.

save ( ImageInterface $image, string $file, null|string $type = null, null|string $quality = null, bool $interlace = false, int $permission = 0755 ): EditorInterface 
Parameters
image

Instance of Image. Saving the image to a different format will have NO effect on the Image instance.

file

File path where to save the image.

type

The image format to use. Can be null, "gif", "png", or "jpeg". If null, an appropriate format will be chosen based on the output file name in $file.

quality

Quality of image. Applies to JPEG only. Accepts number 0 - 100 where 0 is lowest and 100 is the highest quality. Or null for default. Default quality if null is 75.

interlace

Set to true for progressive JPEG. Applies to JPEG only. Default false.

permission

Default permission when creating non-existing target directory. Default is 0755. Note: Its using PHP's octal notation so you must prepend numbers with zero (0).

Returns
An instance of Editor.
Examples

Opening a PNG and saving it:

use Grafika\Grafika;

$editor = Grafika::createEditor();
$editor->open( $image, 'input.png' );
$editor->save( $image, 'output.png' );

Opening a PNG and saving it as JPEG:

$editor->open( $image, 'input.png' );
$editor->save( $image, 'output.jpg' );

Notice the ".jpg" file extension. Grafika will automatically detect the file type based on the file name.

You can also force saving an image into a specific format despite its file name.

$editor->open( $image, 'input.png' );
$editor->save( $image, 'output.jpg', 'png' );

This will save a PNG image to a file named "output.jpg".

JPEG quality can be set from 0-100. Here we save a JPEG to highest quality with interlacing:

$editor->open( $image, 'input.png' );
$editor->save( $image, 'output.jpg', null, 100, true );

Notice that type is set to null which lets Grafika decide the file type based on the file name like in example 2.

Saving an image to non-existent directory will result to Grafika creating the said directory. The default permission can be changed:

$editor->open( $image, 'input.png' );
$editor->save( $image, '/non-existent-dir/non-existent-dir/output.png', null, null, false, 0777 );

This will create the 2 directories with a permission of 0777.