function image_save

Closes the image and saves the changes to a file.

Parameters

object $image: An image object returned by image_load(). The object's 'info' property will be updated if the file is saved successfully.

$destination: (optional) Destination path where the image should be saved. If it is empty the original image file will be overwritten.

Return value

bool TRUE on success, FALSE on failure.

See also

image_load()

\Drupal\system\Plugin\ImageToolkitInterface::save()

Related topics

4 calls to image_save()
file_validate_image_resolution in drupal/core/modules/file/file.module
Verifies that image dimensions are within the specified maximum and minimum.
image_style_create_derivative in drupal/core/modules/image/image.module
Creates a new image derivative based on an image style.
ToolkitGdTest::testManipulations in drupal/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php
Since PHP can't visually check that our images have been manipulated properly, build a list of expected color values for each of the corners and the expected height and widths for the final images.
ToolkitTest::testSave in drupal/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php
Test the image_save() function.

File

drupal/core/includes/image.inc, line 350
API for manipulating images.

Code

function image_save($image, $destination = NULL) {
  if (empty($destination)) {
    $destination = $image->source;
  }
  if ($return = $image->toolkit
    ->save($image, $destination)) {

    // Clear the cached file size and refresh the image information.
    clearstatcache(TRUE, $destination);
    $image->info = image_get_info($destination, $image->toolkit);
    if (drupal_chmod($destination)) {
      return $return;
    }
  }
  return FALSE;
}