private static function _operate($src, $op, $force = false)
{
if (empty($src)) {
return '';
}
$external = false;
// if external image, load it first
if (URLHelper::is_external_content($src)) {
$src = self::sideload_image($src);
$external = true;
}
// break down URL into components
$au = self::analyze_url($src);
// build URL and filenames
$new_url = self::_get_file_url($au['base'], $au['subdir'], $op->filename($au['filename'], $au['extension']), $au['absolute']);
$destination_path = self::_get_file_path($au['base'], $au['subdir'], $op->filename($au['filename'], $au['extension']));
$source_path = self::_get_file_path($au['base'], $au['subdir'], $au['basename']);
$new_url = apply_filters('timber/image/new_url', $new_url);
$destination_path = apply_filters('timber/image/new_path', $destination_path);
// if already exists...
if (file_exists($destination_path)) {
if ($force || filemtime($source_path) > filemtime($destination_path)) {
// Force operation - warning: will regenerate the image on every pageload, use for testing purposes only!
unlink($destination_path);
} else {
// return existing file (caching)
return $new_url;
}
}
// otherwise generate result file
if ($op->run($source_path, $destination_path)) {
if (get_class($op) === 'Timber\\Image\\Operation\\Resize' && $external) {
$new_url = strtolower($new_url);
}
return $new_url;
} else {
// in case of error, we return source file itself
return $src;
}
}