function image_tinypng_save in TinyPNG 7
GD helper to write an image resource to a destination file.
Parameters
$image: An image object.
$destination: A string file URI or path where the image should be saved.
Return value
TRUE or FALSE, based on success.
See also
File
- ./
tinypng.module, line 153 - Provides TinyPNG integration.
Code
function image_tinypng_save(stdClass $image, $destination) {
$res = _tinypng_fallback('save', $image, $destination);
$supported_types = array(
'image/png',
'image/jpg',
'image/jpeg',
);
if (!in_array($image->info['mime_type'], $supported_types)) {
return $res;
}
try {
if (tinypng_load_library()) {
$dest = drupal_realpath($destination);
$res = Tinify\fromFile($dest)
->toFile($dest);
}
} catch (Exception $e) {
watchdog('tinypng', $e
->getMessage(), array(), WATCHDOG_ERROR);
}
return $res;
}