/** * Hook: generates HiDPI image during thumbnail generation * @param string $image_path * @param boolean $lazy * @param string $filename * @param int $width * @param int $height */ function fn_hidpi_generate_thumbnail_file_pre($image_path, $lazy, $filename, $width, $height) { if ($lazy == false) { list(, , , $tmp_path) = fn_get_image_size(fn_hdpi_form_name(Storage::instance('images')->getAbsolutePath($image_path))); if (!empty($tmp_path)) { list($cont, $format) = fn_resize_image($tmp_path, $width * 2, $height * 2, Registry::get('settings.Thumbnails.thumbnail_background_color')); if (!empty($cont)) { $_filename = fn_hdpi_form_name($filename, $format); Storage::instance('images')->put($_filename, array('contents' => $cont, 'caching' => true, 'keep_origins' => true)); } } } }
/** * Generate thumbnail with given size from image * * @param string $image_path Path to image * @param int $width Thumbnail width * @param int $height Thumbnail height * @param bool $lazy lazy generation - returns script URL that generates thumbnail * @return array array with width, height, mime type and path */ function fn_generate_thumbnail($image_path, $width, $height = 0, $lazy = false) { /** * Actions before thumbnail generate * * @param string $image_path Path to image * @param int $width Width of thumbnail * @param int $height Height of thumbnail * @param bool $make_box If true create rectangle border */ fn_set_hook('generate_thumbnail_pre', $image_path, $width, $height, $make_box); if (empty($image_path)) { return ''; } $filename = 'thumbnails/' . $width . (empty($height) ? '' : '/' . $height) . '/' . $image_path; if (Registry::get('settings.Thumbnails.convert_to') != 'original') { $filename = preg_replace("/\\.[^.]*?\$/", "." . Registry::get('settings.Thumbnails.convert_to'), $filename); } $th_filename = ''; if ($lazy || Storage::instance('images')->isExist($filename)) { $th_filename = $filename; } else { // for lazy thumbnails: find original filename if (Registry::get('config.tweaks.lazy_thumbnails') && Registry::get('settings.Thumbnails.convert_to') != 'original' && !Storage::instance('images')->isExist($image_path)) { foreach (array('png', 'jpg', 'jpeg') as $ext) { $image_path = preg_replace("/\\.[^.]*?\$/", "." . $ext, $image_path); if (Storage::instance('images')->isExist($image_path)) { break; } } } /** * Actions before thumbnail generate, if thumbnail is not exists, after validations * * @param string $real_path Real path to image * @param string $lazy lazy generation - returns script URL that generates thumbnail */ fn_set_hook('generate_thumbnail_file_pre', $image_path, $lazy, $filename, $width, $height); list(, , , $tmp_path) = fn_get_image_size(Storage::instance('images')->getAbsolutePath($image_path)); if (!empty($tmp_path)) { list($cont, $format) = fn_resize_image($tmp_path, $width, $height, Registry::get('settings.Thumbnails.thumbnail_background_color')); if (!empty($cont)) { list(, $th_filename) = Storage::instance('images')->put($filename, array('contents' => $cont, 'caching' => true)); } } } /** * Actions after thumbnail generate * * @param string $th_filename Thumbnail path * @param string $lazy lazy generation - returns script URL that generates thumbnail */ fn_set_hook('generate_thumbnail_post', $th_filename, $lazy); return !empty($th_filename) ? Storage::instance('images')->getUrl($th_filename) : ''; }
function fn_generate_thumbnail($image_path, $width, $height = 0, $make_box = false, $force = null) { if (empty($image_path)) { return ''; } if (strpos($image_path, '://') === false) { if (strpos($image_path, '/') !== 0) { // relative path $image_path = Registry::get('config.current_path') . '/' . $image_path; } $image_path = (defined('HTTPS') ? 'https://' . Registry::get('config.https_host') : 'http://' . Registry::get('config.http_host')) . $image_path; } $_path = str_replace(Registry::get('config.current_location') . '/', '', $image_path); $image_url = explode('/', $_path); $image_name = array_pop($image_url); $image_dir = array_pop($image_url); $image_dir .= '/' . $width . (empty($height) ? '' : '/' . $height); $filename = $image_dir . '/' . $image_name; $real_path = htmlspecialchars_decode(DIR_ROOT . '/' . $_path, ENT_QUOTES); $th_path = htmlspecialchars_decode(DIR_THUMBNAILS . $filename, ENT_QUOTES); if (!fn_mkdir(DIR_THUMBNAILS . $image_dir)) { return ''; } if (!file_exists($th_path) || $force != null) { if (fn_get_image_size($real_path)) { $image = fn_get_contents($real_path); fn_put_contents($th_path, $image); if ($force == "new") { fn_place_new($th_path); } fn_resize_image($th_path, $th_path, $width, $height, $make_box); } else { return ''; } } return Registry::get('config.thumbnails_path') . $filename; }
$c->Create(); exit; } elseif ($mode == 'custom_image') { if (empty($_REQUEST['image'])) { exit; } $type = empty($_REQUEST['type']) ? 'T' : $_REQUEST['type']; $image_path = 'sess_data/' . fn_basename($_REQUEST['image']); if (Storage::instance('custom_files')->isExist($image_path)) { $real_path = Storage::instance('custom_files')->getAbsolutePath($image_path); list(, , $image_type, $tmp_path) = fn_get_image_size($real_path); if ($type == 'T') { $thumb_path = $image_path . '_thumb'; if (!Storage::instance('custom_files')->isExist($thumb_path)) { // Output a thumbnail image list($cont, $format) = fn_resize_image($tmp_path, Registry::get('settings.Thumbnails.product_lists_thumbnail_width'), Registry::get('settings.Thumbnails.product_lists_thumbnail_height'), Registry::get('settings.Thumbnails.thumbnail_background_color')); if (!empty($cont)) { Storage::instance('custom_files')->put($thumb_path, array('contents' => $cont)); } } $real_path = Storage::instance('custom_files')->getAbsolutePath($thumb_path); } header('Content-type: ' . $image_type); fn_echo(fn_get_contents($real_path)); exit; } // Not image file. Display spacer instead. header('Content-type: image/gif'); readfile(fn_get_theme_path('[themes]/[theme]') . '/media/images/spacer.gif'); exit; } elseif ($mode == 'thumbnail') {
} if (!empty($verification_settings['background_image'])) { $c->SetBackgroundImages(DIR_ROOT . '/' . $verification_settings['background_image']); } $c->Create(); exit; } elseif ($mode == 'custom_image') { if (empty($_REQUEST['image'])) { exit; } $type = empty($_REQUEST['type']) ? 'T' : $_REQUEST['type']; $image_path = DIR_CUSTOM_FILES . 'sess_data/' . basename($_REQUEST['image']); if (file_exists($image_path)) { $image_info = getimagesize($image_path); if (!empty($image_info)) { if ($type == 'T') { // Output a thumbnail image if (fn_resize_image($image_path, $image_path . '_thumb', Registry::get('settings.Thumbnails.product_lists_thumbnail_width'), Registry::get('settings.Thumbnails.product_lists_thumbnail_height'))) { $image_path .= '_thumb'; } } header('Content-type: ' . $image_info['mime']); readfile($image_path); exit; } } // Not image file. Display spacer instead. header('Content-type: image/gif'); readfile(DIR_SKINS . Registry::get('config.skin_name') . '/customer/images/spacer.gif'); exit; }