/** * flagAdmin::webview_image() - create a new image, based on the height /width * * @class flagAdmin * @param object | int $image contain all information about the image or the id * @return string result code */ public static function webview_image($image) { global $flag; if (is_numeric($image)) { $image = flagdb::find_image($image); } if (!is_object($image)) { return __('Object didn\'t contain correct data', 'flag'); } $img_size = @getimagesize($image->imagePath); $dest_path = dirname($image->webimagePath); if (flagGallery::create_webview_folder(dirname($image->imagePath))) { if (!is_writable($dest_path)) { @chmod($dest_path, 0755); } if (file_exists($image->webimagePath)) { return '1'; } $imgquality = $flag->options['imgQuality']; $max_width = $img_size[0] < 1200 ? $img_size[0] : 1200; $max_height = $img_size[1] < 1200 ? $img_size[1] : 1200; if (function_exists('wp_get_image_editor')) { $editor = wp_get_image_editor($image->imagePath); $editor->set_quality($imgquality); $editor->resize($max_width, $max_height, 0); $editor->save($image->webimagePath); if (@filesize($image->webimagePath) > @filesize($image->imagePath)) { @copy($image->imagePath, $image->webimagePath); } $webviewsize = @getimagesize($image->webimagePath); flagdb::update_image_meta($image->pid, array('webview' => $webviewsize)); do_action('flag_image_optimized', $image); } } return '1'; }