/** * 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)); } } } }
public static final function getApiImageData($image_pair, $type = 'product', $image_type = 'icon', $params = array()) { if (empty($image_pair)) { return false; } if ($image_type == 'detailed' and !empty($image_pair['detailed_id']) or empty($image_pair['image_id']) or !empty($image_pair['image_id']) and empty($image_pair['icon'])) { $icon = isset($image_pair['detailed']) ? $image_pair['detailed'] : array(); } elseif (!empty($image_pair['image_id'])) { $icon = $image_pair['icon']; } $icon['pair_id'] = $image_pair['pair_id']; if (isset($params['width']) && isset($params['height']) && !empty($icon['image_x']) && !empty($icon['image_y']) && $icon['image_x'] > 0 && $icon['image_y'] > 0 && ($icon['image_x'] > $params['width'] || $icon['image_y'] > $params['width'])) { $path = version_compare(PRODUCT_VERSION, '4.0.2', '<') ? $icon['image_path'] : $icon['relative_path']; $width = $params['width']; $height = $params['height']; // To avoid making box if (isset($params['keep_proportions'])) { if ($icon['image_x'] > $icon['image_y']) { $height = 0; } else { $width = 0; } } $icon['url'] = fn_generate_thumbnail($path, $width, $height); $real_path = $icon['absolute_path']; $size = fn_get_image_size($real_path); $icon['image_y'] = $size ? $size[0] : $params['height']; $icon['image_x'] = $size ? $size[1] : $params['width']; } else { $icon['url'] = $icon['image_path']; } // Delete unnecessary fields if (isset($icon['absolute_path'])) { unset($icon['absolute_path']); } return $icon; }
/** * 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_companies_update_logos($company_id, $old_logos) { $logotypes = fn_filter_uploaded_data('logotypes'); $areas = fn_companies_get_manifest_definition(); // Update company logotypes if (!empty($logotypes)) { $logos = $old_logos; foreach ($logotypes as $type => $logo) { $area = $areas[$type]; $short_name = "company/{$company_id}/{$type}_{$logo['name']}"; $filename = DIR_IMAGES . $short_name; fn_mkdir(dirname($filename)); if (fn_copy($logo['path'], $filename)) { list($w, $h, ) = fn_get_image_size($filename); $logos[$area['name']] = array('vendor' => 1, 'filename' => $short_name, 'width' => $w, 'height' => $h); } else { $text = fn_get_lang_var('text_cannot_create_file'); $text = str_replace('[file]', $filename, $text); fn_set_notification('E', fn_get_lang_var('error'), $text); } @unlink($logo['path']); } $logos = serialize($logos); db_query("UPDATE ?:companies SET logos = ?s WHERE company_id = ?i", $logos, $company_id); } fn_save_logo_alt($areas, $company_id); }
$c->SetCharSet(fn_array_merge(range('A', 'F'), array(2, 3, 4, 5, 6, 8, 9), false)); } if (!empty($verification_settings['background_image'])) { $c->SetBackgroundImages(fn_get_files_dir_path() . $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 = '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; }
fn_rm(DIR_COMPILED . 'customer', false); fn_rm(DIR_COMPILED . 'admin', false); $suffix = '.design_mode'; } if ($mode == 'update_logos') { $logos = fn_filter_uploaded_data('logotypes'); $areas = fn_get_manifest_definition(); fn_save_logo_alt($areas); // Update customer logotype if (!empty($logos)) { foreach ($logos as $type => $logo) { $area = $areas[$type]; $manifest = parse_ini_file(DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . SKIN_MANIFEST, true); $filename = DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . $area['path'] . '/images/' . $logo['name']; if (fn_copy($logo['path'], $filename)) { list($w, $h, ) = fn_get_image_size($filename); $manifest[$area['name']]['filename'] = $logo['name']; $manifest[$area['name']]['width'] = $w; $manifest[$area['name']]['height'] = $h; fn_write_ini_file(DIR_SKINS . Registry::get('settings.skin_name_' . $area['skin']) . '/' . SKIN_MANIFEST, $manifest); } else { $text = fn_get_lang_var('text_cannot_create_file'); $text = str_replace('[file]', $filename, $text); fn_set_notification('E', fn_get_lang_var('error'), $text); } @unlink($logo['path']); } } $suffix = '.logos'; } return array(CONTROLLER_STATUS_OK, "site_layout" . $suffix);
function fn_attach_images($body, &$mailer) { $http_location = Registry::get('config.http_location'); $https_location = Registry::get('config.https_location'); $http_path = Registry::get('config.http_path'); $https_path = Registry::get('config.https_path'); $files = array(); if (preg_match_all("/(?<=\\ssrc=|\\sbackground=)('|\")(.*)\\1/SsUi", $body, $matches)) { $files = fn_array_merge($files, $matches[2], false); } if (preg_match_all("/(?<=\\sstyle=)('|\").*url\\(('|\"|\\\\\\1)(.*)\\2\\).*\\1/SsUi", $body, $matches)) { $files = fn_array_merge($files, $matches[3], false); } if (empty($files)) { return $body; } else { $files = array_unique($files); foreach ($files as $k => $_path) { $cid = 'csimg' . $k; $path = str_replace('&', '&', $_path); $real_path = ''; // Replace url path with filesystem if this url is NOT dynamic if (strpos($path, '?') === false && strpos($path, '&') === false) { if (($i = strpos($path, $http_location)) !== false) { $real_path = substr_replace($path, DIR_ROOT, $i, strlen($http_location)); } elseif (($i = strpos($path, $https_location)) !== false) { $real_path = substr_replace($path, DIR_ROOT, $i, strlen($https_location)); } elseif (!empty($http_path) && ($i = strpos($path, $http_path)) !== false) { $real_path = substr_replace($path, DIR_ROOT, $i, strlen($http_path)); } elseif (!empty($https_path) && ($i = strpos($path, $https_path)) !== false) { $real_path = substr_replace($path, DIR_ROOT, $i, strlen($https_path)); } } if (empty($real_path)) { $real_path = strpos($path, '://') === false ? $http_location . '/' . $path : $path; } list($width, $height, $mime_type) = fn_get_image_size($real_path); if (!empty($width)) { $cid .= '.' . fn_get_image_extension($mime_type); $content = fn_get_contents($real_path); $mailer->AddImageStringAttachment($content, $cid, 'base64', $mime_type); $body = preg_replace("/(['\"])" . str_replace("/", "\\/", preg_quote($_path)) . "(['\"])/Ss", "\\1cid:" . $cid . "\\2", $body); } } } return $body; }
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; }
} fn_set_notification('N', fn_get_lang_var('notice'), fn_get_lang_var($res ? 'text_permissions_changed' : 'error_permissions_not_changed')); Registry::get('ajax')->assign('action_type', $res ? '' : 'error'); exit; } elseif ($mode == 'get_file') { $file = basename($_REQUEST['file']); if (!in_array(fn_get_file_ext($file), Registry::get('config.forbidden_file_extensions'))) { $pname = fn_normalize_path(DIR_SKINS . $current_path); fn_get_file($pname . $file); } exit; } elseif ($mode == 'edit') { $file = basename($_REQUEST['file']); $fname = fn_normalize_path(DIR_SKINS . $current_path . $file); if (!in_array(fn_get_file_ext($fname), Registry::get('config.forbidden_file_extensions'))) { if (fn_get_image_size($fname)) { $ajax->assign('img', Registry::get('config.http_location') . str_replace(DIR_ROOT, '', $fname)); } else { $ajax->assign('content', fn_get_contents($fname)); } } exit; } elseif ($mode == 'restore') { $copied = false; $file = basename($_REQUEST['file']); $c_name = fn_normalize_path(DIR_SKINS . $current_path . $file); $b_path = fn_normalize_path($current_path); // First, try to restore object from the base repository $arr = explode('/', $b_path); $arr[0] = 'base'; $b_path = implode('/', $arr);
function fn_watermark_create($source_filepath, $target_filepath, $is_detailed = false, $company_id = null, $generate_watermark = true) { $original_abs_path = Storage::instance('images')->getAbsolutePath($source_filepath); list(, , , $original_abs_path) = fn_get_image_size($original_abs_path); if (!$generate_watermark) { Storage::instance('images')->put($target_filepath, array('file' => $original_abs_path, 'keep_origins' => true)); return true; } $settings = fn_get_watermark_settings($company_id); if (empty($settings)) { return false; } list($settings['horizontal_position'], $settings['vertical_position']) = explode('_', $settings['position']); /** @var \Imagine\Image\ImagineInterface $imagine */ $imagine = Tygh::$app['image']; try { $image = $imagine->open($original_abs_path); $image->usePalette(new \Imagine\Image\Palette\RGB()); $filter = $imagine instanceof \Imagine\Gd\Imagine ? \Imagine\Image\ImageInterface::FILTER_UNDEFINED : \Imagine\Image\ImageInterface::FILTER_LANCZOS; if ($settings['type'] == WATERMARK_TYPE_GRAPHIC) { $watermark_image_file_path = false; if ($is_detailed) { if (!empty($settings['image_pair']['detailed']['absolute_path'])) { $watermark_image_file_path = $settings['image_pair']['detailed']['absolute_path']; } } elseif (!empty($settings['image_pair']['icon']['absolute_path'])) { $watermark_image_file_path = $settings['image_pair']['icon']['absolute_path']; } if (!$watermark_image_file_path) { return false; } list(, , , $watermark_image_file_path) = fn_get_image_size($watermark_image_file_path); $watermark_image = $imagine->open($watermark_image_file_path); $watermark_image->usePalette(new \Imagine\Image\Palette\RGB()); // Watermark image > canvas image $watermark_size = $watermark_image->getSize()->increase(WATERMARK_PADDING); if (!$image->getSize()->contains($watermark_size)) { $ratio = min(array($image->getSize()->getWidth() / $watermark_size->getWidth(), $image->getSize()->getHeight() / $watermark_size->getHeight())); $watermark_image->resize($watermark_size->scale($ratio), $filter); } $watermark_position = ImageHelper::positionLayerOnCanvas($image->getSize(), $watermark_image->getSize(), $settings['horizontal_position'], $settings['vertical_position'], new \Imagine\Image\Box(WATERMARK_PADDING, WATERMARK_PADDING)); $image->paste($watermark_image, $watermark_position); } elseif ($settings['type'] == WATERMARK_TYPE_TEXT) { $font_path = Registry::get('config.dir.lib') . 'other/fonts/' . $settings['font'] . '.ttf'; $font_size = $is_detailed ? $settings['font_size_detailed'] : $settings['font_size_icon']; $font_alpha_blend = 100; switch ($settings['font_color']) { case 'white': $font_color = array(255, 255, 255); break; case 'black': $font_color = array(0, 0, 0); break; case 'gray': $font_color = array(120, 120, 120); break; case 'clear_gray': default: $font_color = array(120, 120, 120); $font_alpha_blend = WATERMARK_FONT_ALPHA; break; } $font = $imagine->font($font_path, $font_size, $image->palette()->color($font_color, $font_alpha_blend)); $text_layer_size = ImageHelper::calculateTextSize($settings['text'], $font); $watermark_position = ImageHelper::positionLayerOnCanvas($image->getSize(), $text_layer_size, $settings['horizontal_position'], $settings['vertical_position'], new \Imagine\Image\Box(WATERMARK_PADDING, WATERMARK_PADDING)); $image->draw()->text($settings['text'], $font, $watermark_position); } $settings = Settings::instance()->getValues('Thumbnails'); $options = array('jpeg_quality' => $settings['jpeg_quality'], 'png_compression_level' => 9, 'filter' => $filter); if ($original_file_type = fn_get_image_extension(fn_get_mime_content_type($original_abs_path, false))) { $format = $original_file_type; } else { $format = 'png'; } Storage::instance('images')->put($target_filepath, array('contents' => $image->get($format, $options))); return true; } catch (\Exception $e) { return false; } }
/** * Converts images links to image:data attribute * @param string $html html code * @return string html code with converted links */ protected static function convertImages($html) { $http_location = Registry::get('config.http_location'); $https_location = Registry::get('config.https_location'); $http_path = Registry::get('config.http_path'); $https_path = Registry::get('config.https_path'); $files = array(); if (preg_match_all("/(?<=\\ssrc=|\\sbackground=)('|\")(.*)\\1/SsUi", $html, $matches)) { $files = fn_array_merge($files, $matches[2], false); } if (preg_match_all("/(?<=\\sstyle=)('|\").*url\\(('|\"|\\\\\\1)(.*)\\2\\).*\\1/SsUi", $html, $matches)) { $files = fn_array_merge($files, $matches[3], false); } if (empty($files)) { return $html; } else { $files = array_unique($files); foreach ($files as $k => $_path) { $path = str_replace('&', '&', $_path); $real_path = ''; // Replace url path with filesystem if this url is NOT dynamic if (strpos($path, '?') === false && strpos($path, '&') === false) { if (($i = strpos($path, $http_location)) !== false) { $real_path = substr_replace($path, Registry::get('config.dir.root'), $i, strlen($http_location)); } elseif (($i = strpos($path, $https_location)) !== false) { $real_path = substr_replace($path, Registry::get('config.dir.root'), $i, strlen($https_location)); } elseif (!empty($http_path) && ($i = strpos($path, $http_path)) !== false) { $real_path = substr_replace($path, Registry::get('config.dir.root'), $i, strlen($http_path)); } elseif (!empty($https_path) && ($i = strpos($path, $https_path)) !== false) { $real_path = substr_replace($path, Registry::get('config.dir.root'), $i, strlen($https_path)); } } if (empty($real_path)) { $real_path = strpos($path, '://') === false ? $http_location . '/' . $path : $path; } list($width, $height, $mime_type) = fn_get_image_size($real_path); if (!empty($width)) { $content = fn_get_contents($real_path); $html = preg_replace("/(['\"])" . str_replace("/", "\\/", preg_quote($_path)) . "(['\"])/Ss", "\\1data:{$mime_type};base64," . base64_encode($content) . "\\2", $html); } } } return $html; }
function fn_watermark_create($original_image, $watermarked_image, $is_detailed = false, $company_id = null, $generate_watermark = true) { $w_settings = fn_get_watermark_settings($company_id); if (empty($w_settings)) { return false; } $original_abs_path = Storage::instance('images')->getAbsolutePath($original_image); list($w_settings['horizontal_position'], $w_settings['vertical_position']) = explode('_', $w_settings['position']); list($original_width, $original_height, $original_mime_type) = fn_get_image_size($original_abs_path); if (empty($original_width) || empty($original_height)) { return false; } if (!($image = fn_create_image_from_file($original_abs_path, $original_mime_type))) { return false; } if (!$generate_watermark) { Storage::instance('images')->put($watermarked_image, array('file' => $original_abs_path, 'keep_origins' => true)); return true; } $dest_x = $dest_y = $watermark_width = $watermark_height = 0; if ($w_settings['type'] == 'G') { $watermark_image = false; if ($is_detailed) { if (!empty($w_settings['image_pair']['detailed']['absolute_path'])) { $watermark_image = $w_settings['image_pair']['detailed']['absolute_path']; } } elseif (!empty($w_settings['image_pair']['icon']['absolute_path'])) { $watermark_image = $w_settings['image_pair']['icon']['absolute_path']; } list($watermark_width, $watermark_height, $watermark_mime_type) = fn_get_image_size($watermark_image); if (empty($watermark_image) || !($watermark = fn_create_image_from_file($watermark_image, $watermark_mime_type))) { return false; } } else { $font_path = Registry::get('config.dir.lib') . 'other/fonts/' . $w_settings['font'] . '.ttf'; if (!is_file($font_path) || empty($w_settings['text'])) { return false; } if ($is_detailed) { $font_size = $w_settings['font_size_detailed']; } else { $font_size = $w_settings['font_size_icon']; } if (empty($font_size)) { return false; } $ttfbbox = imagettfbbox($font_size, 0, $font_path, $w_settings['text']); $watermark_height = abs($ttfbbox[7]); $watermark_width = abs($ttfbbox[2]); } if (empty($watermark_width) || empty($watermark_height)) { return false; } // Paddings $delta_x = 3; $delta_y = 3; $new_wt_width = $watermark_width; $new_wt_height = $watermark_height; if ($new_wt_width + $delta_x > $original_width) { $new_wt_height = $new_wt_height * ($original_width - $delta_x) / $new_wt_width; $new_wt_width = $original_width - $delta_x; } if ($new_wt_height > $original_height) { $new_wt_width = $new_wt_width * ($original_height - $delta_y) / $new_wt_height; $new_wt_height = $original_height - $delta_y; } if ($w_settings['vertical_position'] == 'top') { $dest_y = $delta_y; } elseif ($w_settings['vertical_position'] == 'center') { $dest_y = (int) (($original_height - $new_wt_height) / 2); } elseif ($w_settings['vertical_position'] == 'bottom') { $dest_y = $original_height - $new_wt_height - $delta_y; } if ($w_settings['horizontal_position'] == 'left') { $dest_x = $delta_x; } elseif ($w_settings['horizontal_position'] == 'center') { $dest_x = (int) (($original_width - $new_wt_width) / 2); } elseif ($w_settings['horizontal_position'] == 'right') { $dest_x = $original_width - $new_wt_width - $delta_x; } if ($dest_x < 1) { $dest_x = 1; } if ($dest_y < 1) { $dest_y = 1; } if ($w_settings['type'] == 'G') { imagecolortransparent($watermark, imagecolorat($watermark, 0, 0)); if (function_exists('imageantialias')) { imageantialias($image, true); } $result = imagecopyresampled($image, $watermark, $dest_x, $dest_y, 0, 0, $new_wt_width, $new_wt_height, $watermark_width, $watermark_height); imagedestroy($watermark); } else { if ($w_settings['font_color'] == 'white') { $font_color = imagecolorallocate($image, 255, 255, 255); } elseif ($w_settings['font_color'] == 'black') { $font_color = imagecolorallocate($image, 0, 0, 0); } elseif ($w_settings['font_color'] == 'gray') { $font_color = imagecolorallocate($image, 120, 120, 120); } elseif ($w_settings['font_color'] == 'clear_gray') { $font_color = imagecolorallocatealpha($image, 120, 120, 120, WATERMARK_FONT_ALPHA); } $result = imagettftext($image, $font_size, 0, $dest_x, $dest_y + $font_size, $font_color, $font_path, $w_settings['text']); } if ($result === false) { return false; } $ext = fn_get_image_extension($original_mime_type); ob_start(); if ($ext == 'gif') { $result = imagegif($image); } elseif ($ext == 'jpg') { $result = imagejpeg($image, null, 85); } elseif ($ext == 'png') { $result = imagepng($image, null, 8); } $content = ob_get_clean(); imagedestroy($image); Storage::instance('images')->put($watermarked_image, array('contents' => $content)); return $result; }
private static final function getApiImageBinData($icon, $params, $type = 'product') { if (!empty($icon['absolute_path'])) { $image_file = $icon['absolute_path']; } else { $_image_file = db_get_field("SELECT image_path FROM ?:images WHERE image_id = ?i", $params['image_id']); $image_file = Registry::get('config.dir.images') . $type . '/' . $_image_file; } if (extension_loaded('gd') && (!empty($params['image_x']) || !empty($params['image_y']))) { $new_image_x = !empty($params['image_x']) ? $params['image_x'] : $params['image_y'] / $icon['image_y'] * $icon['image_x']; $new_image_y = !empty($params['image_y']) ? $params['image_y'] : $params['image_x'] / $icon['image_x'] * $icon['image_y']; $new_image_gd = imagecreatetruecolor($new_image_x, $new_image_y); list(, , $mime_type) = fn_get_image_size($image_file); $ext = fn_get_image_extension($mime_type); if ($ext == 'gif' && function_exists('imagegif')) { $image_gd = imagecreatefromgif($image_file); } elseif ($ext == 'jpg' && function_exists('imagejpeg')) { $image_gd = imagecreatefromjpeg($image_file); } elseif ($ext == 'png' && function_exists('imagepng')) { $image_gd = imagecreatefrompng($image_file); } else { return false; } imagecopyresized($new_image_gd, $image_gd, 0, 0, 0, 0, $new_image_x, $new_image_y, $icon['image_x'], $icon['image_y']); $tmp_file = fn_create_temp_file(); if ($ext == 'gif') { imagegif($new_image_gd, $tmp_file); } elseif ($ext == 'jpg') { imagejpeg($new_image_gd, $tmp_file, 50); } elseif ($ext == 'png') { imagepng($new_image_gd, $tmp_file, 0); } if (!($image_data = fn_get_contents($tmp_file))) { return false; } $icon['data'] = base64_encode($image_data); $icon['image_x'] = $new_image_x; $icon['image_y'] = $new_image_y; } elseif (fn_get_contents($image_file)) { $image_data = fn_get_contents($image_file); $icon['data'] = base64_encode($image_data); } return $icon; }