image_save

7 image.inc image_save(stdClass $image, $destination = NULL)
8 image.inc image_save(stdClass $image, $destination = NULL)

Close the image and save the changes to a file.

Parameters

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

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

Return value

TRUE on success, FALSE on failure.

See also

image_load()

image_gd_save()

Related topics

4 calls to image_save()

File

includes/image.inc, line 418
API for manipulating images.

Code

function image_save(stdClass $image, $destination = NULL) {
  if (empty($destination)) {
    $destination = $image->source;
  }
  if ($return = image_toolkit_invoke('save', $image, array($destination))) {
    // Clear the cached file size and refresh the image information.
    clearstatcache();
    $image->info = image_get_info($destination, $image->toolkit);

    if (drupal_chmod($destination)) {
      return $return;
    }
  }
  return FALSE;
}

Comments

resize image uploaded another folder

When $destination is not null then problem occur: " Unable to open 'C:\xampp\htdocs\seedhaka\sites\default\files\uploads\thumbs' for writing: Permission denied in image_gd_save() (line 272 of C:\xampp\htdocs\seedhaka\modules\system\image.gd.inc). "

Any one help?

$filepath =  'public://uploads';
$file = file_save_upload('logo',$validators, $filepath, FILE_EXISTS_REPLACE);

   $file_name = $file->filename;
    $file_size = $file->filesize;
    $fid = $file->fid;

    $file = file_load($fid);
    $image = image_load($file->uri);
   
    $scaled = image_resize($image, 100, 80); // it returns TRUE
    // OR image_crop()
   
   
    image_save($image, $filepath.'/thumbs/');

Login or register to post comments