本文整理匯總了PHP中ImageManager::checkImageMemoryLimit方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageManager::checkImageMemoryLimit方法的具體用法?PHP ImageManager::checkImageMemoryLimit怎麽用?PHP ImageManager::checkImageMemoryLimit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ImageManager
的用法示例。
在下文中一共展示了ImageManager::checkImageMemoryLimit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: thumbnail
/**
* Generate a cached thumbnail for object lists (eg. carrier, order states...etc)
*
* @param string $image Real image filename
* @param string $cache_image Cached filename
* @param int $size Desired size
* @param string $image_type Image type
* @param bool $disable_cache When turned on a timestamp will be added to the image URI to disable the HTTP cache
* @return string
*/
public static function thumbnail($image, $cache_image, $size, $image_type = 'jpg', $disable_cache = false)
{
if (!file_exists($image)) {
return '';
}
if (!file_exists(_PS_TMP_IMG_DIR_ . $cache_image)) {
$infos = getimagesize($image);
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($image)) {
return false;
}
$x = $infos[0];
$y = $infos[1];
$max_x = $size * 3;
// Size is already ok
if ($y < $size && $x <= $max_x) {
copy($image, _PS_TMP_IMG_DIR_ . $cache_image);
} else {
$ratio_x = $x / ($y / $size);
if ($ratio_x > $max_x) {
$ratio_x = $max_x;
$size = $y / ($x / $max_x);
}
ImageManager::resize($image, _PS_TMP_IMG_DIR_ . $cache_image, $ratio_x, $size, $image_type);
}
}
return '<img src="' . _PS_TMP_IMG_ . $cache_image . (!$disable_cache ? '?time=' . time() : '') . '" alt="" class="imgm" />';
}
示例2: thumbnail
/**
* Generate a cached thumbnail for object lists (eg. carrier, order states...etc)
*
* @param string $image Real image filename
* @param string $cache_image Cached filename
* @param int $size Desired size
* @param string $image_type Image type
* @param bool $disable_cache When turned on a timestamp will be added to the image URI to disable the HTTP cache
* @return string
*/
public static function thumbnail($image, $cache_image, $size, $image_type = 'jpg', $disable_cache = false)
{
if (!file_exists($image)) {
return '';
}
if (!file_exists(_PS_TMP_IMG_DIR_ . $cache_image)) {
$infos = getimagesize($image);
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($image)) {
return false;
}
$x = $infos[0];
$y = $infos[1];
$max_x = $size * 3;
// Size is already ok
if ($y < $size && $x <= $max_x) {
copy($image, _PS_TMP_IMG_DIR_ . $cache_image);
} else {
$ratio_x = $x / ($y / $size);
if ($ratio_x > $max_x) {
$ratio_x = $max_x;
$size = $y / ($x / $max_x);
}
ImageManager::resize($image, _PS_TMP_IMG_DIR_ . $cache_image, $ratio_x, $size, $image_type);
}
}
// Relative link will always work, whatever the base uri set in the admin
if (Context::getContext()->controller->controller_type == 'admin') {
return '<img src="../img/tmp/' . $cache_image . (!$disable_cache ? '?time=' . time() : '') . '" alt="" class="imgm" />';
} else {
return '<img src="' . _PS_TMP_IMG_ . $cache_image . (!$disable_cache ? '?time=' . time() : '') . '" alt="" class="imgm" />';
}
}
示例3: ajaxProcessuploadThumbnailImages
public function ajaxProcessuploadThumbnailImages()
{
$category = new Category((int) Tools::getValue('id_category'));
if (isset($_FILES['thumbnail'])) {
//Get total of image already present in directory
$files = scandir(_PS_CAT_IMG_DIR_);
$assigned_keys = array();
$allowed_keys = array(0, 1, 2);
foreach ($files as $file) {
$matches = array();
if (preg_match('/^' . $category->id . '-([0-9])?_thumb.jpg/i', $file, $matches) === 1) {
$assigned_keys[] = (int) $matches[1];
}
}
$available_keys = array_diff($allowed_keys, $assigned_keys);
$helper = new HelperImageUploader('thumbnail');
$files = $helper->process();
$total_errors = array();
if (count($available_keys) < count($files)) {
$total_errors['name'] = sprintf(Tools::displayError('An error occurred while uploading the image :'));
$total_errors['error'] = sprintf(Tools::displayError('You cannot upload more files'));
die(Tools::jsonEncode(array('thumbnail' => array($total_errors))));
}
foreach ($files as $key => &$file) {
$id = array_shift($available_keys);
$errors = array();
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (isset($file['save_path']) && !ImageManager::checkImageMemoryLimit($file['save_path'])) {
$errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
}
// Copy new image
if (!isset($file['save_path']) || empty($errors) && !ImageManager::resize($file['save_path'], _PS_CAT_IMG_DIR_ . (int) Tools::getValue('id_category') . '-' . $id . '_thumb.jpg')) {
$errors[] = Tools::displayError('An error occurred while uploading the image.');
}
if (count($errors)) {
$total_errors = array_merge($total_errors, $errors);
}
if (isset($file['save_path']) && is_file($file['save_path'])) {
unlink($file['save_path']);
}
//Necesary to prevent hacking
if (isset($file['save_path'])) {
unset($file['save_path']);
}
if (isset($file['tmp_name'])) {
unset($file['tmp_name']);
}
//Add image preview and delete url
$file['image'] = ImageManager::thumbnail(_PS_CAT_IMG_DIR_ . (int) $category->id . '-' . $id . '_thumb.jpg', $this->context->controller->table . '_' . (int) $category->id . '-' . $id . '_thumb.jpg', 100, 'jpg', true, true);
$file['delete_url'] = Context::getContext()->link->getAdminLink('AdminBlockCategories') . '&deleteThumb=' . $id . '&id_category=' . (int) $category->id . '&updatecategory';
}
if (count($total_errors)) {
$this->context->controller->errors = array_merge($this->context->controller->errors, $total_errors);
} else {
Tools::clearSmartyCache();
}
die(Tools::jsonEncode(array('thumbnail' => $files)));
}
}
示例4: uploadImage
protected function uploadImage($id, $name, $dir, $ext = false, $width = null, $height = null)
{
if (isset($_FILES[$name]['tmp_name']) && !empty($_FILES[$name]['tmp_name'])) {
// Delete old image
if (Validate::isLoadedObject($object = $this->loadObject())) {
$object->deleteImage();
} else {
return false;
}
// Check image validity
$max_size = isset($this->max_image_size) ? $this->max_image_size : 0;
if ($error = ImageManager::validateUpload($_FILES[$name], Tools::getMaxUploadSize($max_size))) {
$this->errors[] = $error;
}
$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
if (!$tmp_name) {
return false;
}
if (!move_uploaded_file($_FILES[$name]['tmp_name'], $tmp_name)) {
return false;
}
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($tmp_name)) {
$this->errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
}
// Copy new image
if (empty($this->errors) && !ImageManager::resize($tmp_name, _PS_MODULE_DIR_ . 'possequence' . DS . 'images' . DS . $name . '_' . $id . '.' . $this->imageType, (int) $width, (int) $height, $ext ? $ext : $this->imageType)) {
$this->errors[] = Tools::displayError('An error occurred while uploading the image.');
}
if (count($this->errors)) {
return false;
}
if ($this->afterImageUpload()) {
unlink($tmp_name);
return true;
}
return false;
}
return true;
}
示例5: postImage
/**
* @param Employee $object
*
* @return bool
*/
protected function postImage($id)
{
$ret = parent::postImage($id);
if (isset($_FILES['image']) && isset($_FILES['image']['tmp_name']) && !empty($_FILES['image']['tmp_name'])) {
if ($error = ImageManager::validateUpload($_FILES['image'], 4000000)) {
return $this->displayError($this->l('Invalid image'));
} else {
$path = _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '.' . $this->imageType;
$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS');
if (!$tmp_name) {
return false;
}
if (!move_uploaded_file($_FILES['image']['tmp_name'], $tmp_name)) {
return false;
}
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($tmp_name)) {
$this->errors[] = Tools::displayError('Due to memory limit restrictions, this image cannot be loaded. Please increase your memory_limit value via your server\'s configuration settings. ');
}
// Copy new image
if (empty($this->errors) && !ImageManager::resize($tmp_name, $path, (int) $width, (int) $height, $ext ? $ext : $this->imageType)) {
$this->errors[] = Tools::displayError('An error occurred while uploading the image.');
}
if (count($this->errors)) {
return false;
}
if ($this->afterImageUpload()) {
unlink($tmp_name);
// return true;
}
$posts_types = BlogImageType::GetImageAllType('post');
foreach ($posts_types as $image_type) {
$dir = _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg';
if (file_exists($dir)) {
unlink($dir);
}
}
foreach ($posts_types as $image_type) {
ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/' . $id . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
}
}
}
return $ret;
}
示例6: copyImg
private static function copyImg($id_entity, $id_image = null, $url, $entity = 'products')
{
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
$watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
switch ($entity) {
default:
case 'products':
$image_obj = new Image($id_image);
$path = $image_obj->getPathForCreation();
break;
case 'categories':
$path = _PS_CAT_IMG_DIR_ . (int) $id_entity;
break;
}
$url = str_replace(' ', '%20', trim($url));
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($url)) {
return false;
}
// 'file_exists' doesn't work on distant file, and getimagesize make the import slower.
// Just hide the warning, the traitment will be the same.
if (@copy($url, $tmpfile)) {
ImageManager::resize($tmpfile, $path . '.jpg');
$images_types = ImageType::getImagesTypes($entity);
foreach ($images_types as $image_type) {
ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
}
if (in_array($image_type['id_image_type'], $watermark_types)) {
Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
}
} else {
unlink($tmpfile);
return false;
}
unlink($tmpfile);
return true;
}
示例7: copyImg
/**
* copyImg copy an image located in $url and save it in a path
* according to $entity->$id_entity .
* $id_image is used if we need to add a watermark
*
* @param int $id_entity id of product or category (set in entity)
* @param int $id_image (default null) id of the image if watermark enabled.
* @param string $url path or url to use
* @param string $entity 'products' or 'categories'
* @param bool $regenerate
* @return bool
*/
protected static function copyImg($id_entity, $id_image = null, $url = '', $entity = 'products', $regenerate = true)
{
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
$watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
switch ($entity) {
default:
case 'products':
$image_obj = new Image($id_image);
$path = $image_obj->getPathForCreation();
break;
case 'categories':
$path = _PS_CAT_IMG_DIR_ . (int) $id_entity;
break;
case 'manufacturers':
$path = _PS_MANU_IMG_DIR_ . (int) $id_entity;
break;
case 'suppliers':
$path = _PS_SUPP_IMG_DIR_ . (int) $id_entity;
break;
case 'stores':
$path = _PS_STORE_IMG_DIR_ . (int) $id_entity;
break;
}
$url = urldecode(trim($url));
$parced_url = parse_url($url);
if (isset($parced_url['path'])) {
$uri = ltrim($parced_url['path'], '/');
$parts = explode('/', $uri);
foreach ($parts as &$part) {
$part = rawurlencode($part);
}
unset($part);
$parced_url['path'] = '/' . implode('/', $parts);
}
if (isset($parced_url['query'])) {
$query_parts = array();
parse_str($parced_url['query'], $query_parts);
$parced_url['query'] = http_build_query($query_parts);
}
if (!function_exists('http_build_url')) {
require_once _PS_TOOL_DIR_ . 'http_build_url/http_build_url.php';
}
$url = http_build_url('', $parced_url);
$orig_tmpfile = $tmpfile;
if (Tools::copy($url, $tmpfile)) {
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($tmpfile)) {
@unlink($tmpfile);
return false;
}
$tgt_width = $tgt_height = 0;
$src_width = $src_height = 0;
$error = 0;
ImageManager::resize($tmpfile, $path . '.jpg', null, null, 'jpg', false, $error, $tgt_width, $tgt_height, 5, $src_width, $src_height);
$images_types = ImageType::getImagesTypes($entity, true);
if ($regenerate) {
$previous_path = null;
$path_infos = array();
$path_infos[] = array($tgt_width, $tgt_height, $path . '.jpg');
foreach ($images_types as $image_type) {
$tmpfile = self::get_best_path($image_type['width'], $image_type['height'], $path_infos);
if (ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height'], 'jpg', false, $error, $tgt_width, $tgt_height, 5, $src_width, $src_height)) {
// the last image should not be added in the candidate list if it's bigger than the original image
if ($tgt_width <= $src_width && $tgt_height <= $src_height) {
$path_infos[] = array($tgt_width, $tgt_height, $path . '-' . stripslashes($image_type['name']) . '.jpg');
}
if ($entity == 'products') {
if (is_file(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $id_entity . '.jpg')) {
unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $id_entity . '.jpg');
}
if (is_file(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $id_entity . '_' . (int) Context::getContext()->shop->id . '.jpg')) {
unlink(_PS_TMP_IMG_DIR_ . 'product_mini_' . (int) $id_entity . '_' . (int) Context::getContext()->shop->id . '.jpg');
}
}
}
if (in_array($image_type['id_image_type'], $watermark_types)) {
Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
}
}
}
} else {
@unlink($orig_tmpfile);
return false;
}
unlink($orig_tmpfile);
return true;
}
示例8: resize
/**
* Resize, cut and optimize image
*
* @param string $src_file Image object from $_FILE
* @param string $dst_file Destination filename
* @param integer $dst_width Desired width (optional)
* @param integer $dst_height Desired height (optional)
* @param string $file_type
* @return boolean Operation result
*/
public static function resize($src_file, $dst_file, $dst_width = null, $dst_height = null, $file_type = 'jpg', $force_type = false, &$error = 0)
{
if (PHP_VERSION_ID < 50300) {
clearstatcache();
} else {
clearstatcache(true, $src_file);
}
if (!file_exists($src_file) || !filesize($src_file)) {
return !($error = self::ERROR_FILE_NOT_EXIST);
}
list($src_width, $src_height, $type) = getimagesize($src_file);
// If PS_IMAGE_QUALITY is activated, the generated image will be a PNG with .jpg as a file extension.
// This allow for higher quality and for transparency. JPG source files will also benefit from a higher quality
// because JPG reencoding by GD, even with max quality setting, degrades the image.
if (Configuration::get('PS_IMAGE_QUALITY') == 'png_all' || Configuration::get('PS_IMAGE_QUALITY') == 'png' && $type == IMAGETYPE_PNG && !$force_type) {
$file_type = 'png';
}
if (!$src_width) {
return !($error = self::ERROR_FILE_WIDTH);
}
if (!$dst_width) {
$dst_width = $src_width;
}
if (!$dst_height) {
$dst_height = $src_height;
}
$src_image = ImageManager::create($type, $src_file);
$width_diff = $dst_width / $src_width;
$height_diff = $dst_height / $src_height;
if ($width_diff > 1 && $height_diff > 1) {
$next_width = $src_width;
$next_height = $src_height;
} else {
if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 || !Configuration::get('PS_IMAGE_GENERATION_METHOD') && $width_diff > $height_diff) {
$next_height = $dst_height;
$next_width = round($src_width * $next_height / $src_height);
$dst_width = (int) (!Configuration::get('PS_IMAGE_GENERATION_METHOD') ? $dst_width : $next_width);
} else {
$next_width = $dst_width;
$next_height = round($src_height * $dst_width / $src_width);
$dst_height = (int) (!Configuration::get('PS_IMAGE_GENERATION_METHOD') ? $dst_height : $next_height);
}
}
if (!ImageManager::checkImageMemoryLimit($src_file)) {
return !($error = self::ERROR_MEMORY_LIMIT);
}
$dest_image = imagecreatetruecolor($dst_width, $dst_height);
// If image is a PNG and the output is PNG, fill with transparency. Else fill with white background.
if ($file_type == 'png' && $type == IMAGETYPE_PNG) {
imagealphablending($dest_image, false);
imagesavealpha($dest_image, true);
$transparent = imagecolorallocatealpha($dest_image, 255, 255, 255, 127);
imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $transparent);
} else {
$white = imagecolorallocate($dest_image, 255, 255, 255);
imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $white);
}
imagecopyresampled($dest_image, $src_image, (int) (($dst_width - $next_width) / 2), (int) (($dst_height - $next_height) / 2), 0, 0, $next_width, $next_height, $src_width, $src_height);
return ImageManager::write($file_type, $dest_image, $dst_file);
}
示例9: copyImg
public static function copyImg($id_entity, $id_image = null, $url, $entity = 'products', $regenerate = true)
{
${"GLOBALS"}["kpgioulf"] = "watermark_types";
${"GLOBALS"}["sqfbffujvchq"] = "url";
${"GLOBALS"}["dufhdfuni"] = "image_obj";
${"GLOBALS"}["ikjqcxaancv"] = "id_entity";
${"GLOBALS"}["rqhaxgd"] = "path";
$kqlqvwwl = "id_image";
$txmteutf = "tmpfile";
$omnesyg = "url";
$yghmlgcyfw = "entity";
${${"GLOBALS"}["lchvwgguggm"]} = tempnam(_PS_TMP_IMG_DIR_, "ps_import");
${${"GLOBALS"}["kpgioulf"]} = explode(",", Configuration::get("WATERMARK_TYPES"));
switch (${$yghmlgcyfw}) {
default:
case "products":
${${"GLOBALS"}["dufhdfuni"]} = new Image(${$kqlqvwwl});
${${"GLOBALS"}["vckigj"]} = $image_obj->getPathForCreation();
break;
case "categories":
${${"GLOBALS"}["rqhaxgd"]} = _PS_CAT_IMG_DIR_ . (int) ${${"GLOBALS"}["ikjqcxaancv"]};
break;
}
${${"GLOBALS"}["qqvbhasckjhp"]} = str_replace(" ", "%20", trim(${$omnesyg}));
if (!ImageManager::checkImageMemoryLimit(${${"GLOBALS"}["sqfbffujvchq"]})) {
return false;
}
if (AgileHelper::copy(${${"GLOBALS"}["qqvbhasckjhp"]}, ${${"GLOBALS"}["lchvwgguggm"]})) {
$obcojo = "path";
${"GLOBALS"}["hohhfbh"] = "tmpfile";
ImageManager::resize(${${"GLOBALS"}["hohhfbh"]}, ${$obcojo} . ".jpg");
${${"GLOBALS"}["cuqvuxx"]} = ImageType::getImagesTypes(${${"GLOBALS"}["pewnwwkf"]});
if (${${"GLOBALS"}["megrxj"]}) {
foreach (${${"GLOBALS"}["cuqvuxx"]} as ${${"GLOBALS"}["dgxlnpegptv"]}) {
${"GLOBALS"}["xvjrxhsdjlr"] = "image_type";
${"GLOBALS"}["hyfkhuiwvhco"] = "id_image";
${"GLOBALS"}["ygshbwcbgfb"] = "image_type";
$yyhyyvkc = "watermark_types";
ImageManager::resize(${${"GLOBALS"}["lchvwgguggm"]}, ${${"GLOBALS"}["vckigj"]} . "-" . stripslashes(${${"GLOBALS"}["xvjrxhsdjlr"]}["name"]) . ".jpg", ${${"GLOBALS"}["dgxlnpegptv"]}["width"], ${${"GLOBALS"}["ygshbwcbgfb"]}["height"]);
if (in_array(${${"GLOBALS"}["dgxlnpegptv"]}["id_image_type"], ${$yyhyyvkc})) {
Hook::exec("actionWatermark", array("id_image" => ${${"GLOBALS"}["hyfkhuiwvhco"]}, "id_product" => ${${"GLOBALS"}["uuixwodgh"]}));
}
}
}
} else {
${"GLOBALS"}["xpnbdeoyymr"] = "tmpfile";
unlink(${${"GLOBALS"}["xpnbdeoyymr"]});
return false;
}
unlink(${$txmteutf});
return true;
}
示例10: copyImg15
function copyImg15($id_entity, $id_image = null, $url, $entity = 'products')
{
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
//fichier tempo vide
$watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
switch ($entity) {
default:
case 'products':
$image_obj = new Image($id_image);
$path = $image_obj->getPathForCreation();
break;
case 'categories':
$path = _PS_CAT_IMG_DIR_ . (int) $id_entity;
break;
}
$url = str_replace(' ', '%20', trim($url));
// Evaluate the memory required to resize the image: if it's too much, you can't resize it.
if (!ImageManager::checkImageMemoryLimit($url)) {
return false;
}
//Echo("in routine url, before the copy");
// 'file_exists' doesn't work on distant file, and getimagesize make the import slower.
// Just hide the warning, the traitment will be the same.
//echo(" - Copy image to:".$tmpfile." and then resize in :".$path);
echo " register_globals: " . ini_get('register_globals');
echo " safe_mode: " . ini_get('safe_mode');
echo " allow_url_fopen: " . ini_get('allow_url_fopen');
//if(isset($sourceFile))
//{
//$array_img = explode('/',$sourceFile);
//}
//if(copy($_POST['source'],"img/".end($array_img))){
//echo(" - Copy ".$sourceFile." image to:"._PS_IMG_DIR_.end($array_img)." and then resize in :".$path);
//if(copy($sourceFile,_PS_IMG_DIR_.end($array_img)))
if ($version < 16000) {
if (@copy($url, $tmpfile)) {
ImageManager::resize($tmpfile, $path . '.jpg');
//ImageManager::resize(_PS_IMG_DIR_.end($array_img), $path.'.jpg');
$images_types = ImageType::getImagesTypes($entity);
foreach ($images_types as $image_type) {
ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
}
//ImageManager::resize(_PS_IMG_DIR_.end($array_img), $path.'-'.stripslashes($image_type['name']).'.jpg', $image_type['width'], $image_type['height']);
if (in_array($image_type['id_image_type'], $watermark_types)) {
Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
}
} else {
echo " - @copy failed, please check Apache parameters like safe_mode=off, register_globals=off, allows_url_fopen=true and writting right in /img/tmp and img/p folders";
unlink($tmpfile);
return false;
}
} else {
if (Tools::copy($url, $tmpfile)) {
ImageManager::resize($tmpfile, $path . '.jpg');
//ImageManager::resize(_PS_IMG_DIR_.end($array_img), $path.'.jpg');
$images_types = ImageType::getImagesTypes($entity);
foreach ($images_types as $image_type) {
ImageManager::resize($tmpfile, $path . '-' . stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
}
//ImageManager::resize(_PS_IMG_DIR_.end($array_img), $path.'-'.stripslashes($image_type['name']).'.jpg', $image_type['width'], $image_type['height']);
if (in_array($image_type['id_image_type'], $watermark_types)) {
Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
}
} else {
echo " - @copy failed, please check Apache parameters like safe_mode=off, register_globals=off, allows_url_fopen=true and writting right in /img/tmp and img/p folders";
unlink($tmpfile);
return false;
}
}
unlink($tmpfile);
return true;
}
示例11: resize
/**
* Resize, cut and optimize image
*
* @param string $src_file Image object from $_FILE
* @param string $dst_file Destination filename
* @param int $dst_width Desired width (optional)
* @param int $dst_height Desired height (optional)
* @param string $file_type
* @param bool $force_type
* @param int $error
* @param int $tgt_width
* @param int $tgt_height
* @param int $quality
* @param int $src_width
* @param int $src_height
* @return bool Operation result
*/
public static function resize($src_file, $dst_file, $dst_width = null, $dst_height = null, $file_type = 'jpg', $force_type = false, &$error = 0, &$tgt_width = null, &$tgt_height = null, $quality = 5, &$src_width = null, &$src_height = null)
{
if (PHP_VERSION_ID < 50300) {
clearstatcache();
} else {
clearstatcache(true, $src_file);
}
if (!file_exists($src_file) || !filesize($src_file)) {
return !($error = self::ERROR_FILE_NOT_EXIST);
}
list($tmp_width, $tmp_height, $type) = getimagesize($src_file);
$rotate = 0;
if (function_exists('exif_read_data') && function_exists('mb_strtolower')) {
$exif = @exif_read_data($src_file);
if ($exif && isset($exif['Orientation'])) {
switch ($exif['Orientation']) {
case 3:
$src_width = $tmp_width;
$src_height = $tmp_height;
$rotate = 180;
break;
case 6:
$src_width = $tmp_height;
$src_height = $tmp_width;
$rotate = -90;
break;
case 8:
$src_width = $tmp_height;
$src_height = $tmp_width;
$rotate = 90;
break;
default:
$src_width = $tmp_width;
$src_height = $tmp_height;
}
} else {
$src_width = $tmp_width;
$src_height = $tmp_height;
}
} else {
$src_width = $tmp_width;
$src_height = $tmp_height;
}
// If PS_IMAGE_QUALITY is activated, the generated image will be a PNG with .jpg as a file extension.
// This allow for higher quality and for transparency. JPG source files will also benefit from a higher quality
// because JPG reencoding by GD, even with max quality setting, degrades the image.
if (Configuration::get('PS_IMAGE_QUALITY') == 'png_all' || Configuration::get('PS_IMAGE_QUALITY') == 'png' && $type == IMAGETYPE_PNG && !$force_type) {
$file_type = 'png';
}
if (!$src_width) {
return !($error = self::ERROR_FILE_WIDTH);
}
if (!$dst_width) {
$dst_width = $src_width;
}
if (!$dst_height) {
$dst_height = $src_height;
}
$width_diff = $dst_width / $src_width;
$height_diff = $dst_height / $src_height;
$ps_image_generation_method = Configuration::get('PS_IMAGE_GENERATION_METHOD');
if ($width_diff > 1 && $height_diff > 1) {
$next_width = $src_width;
$next_height = $src_height;
} else {
if ($ps_image_generation_method == 2 || !$ps_image_generation_method && $width_diff > $height_diff) {
$next_height = $dst_height;
$next_width = round($src_width * $next_height / $src_height);
$dst_width = (int) (!$ps_image_generation_method ? $dst_width : $next_width);
} else {
$next_width = $dst_width;
$next_height = round($src_height * $dst_width / $src_width);
$dst_height = (int) (!$ps_image_generation_method ? $dst_height : $next_height);
}
}
if (!ImageManager::checkImageMemoryLimit($src_file)) {
return !($error = self::ERROR_MEMORY_LIMIT);
}
$tgt_width = $dst_width;
$tgt_height = $dst_height;
$dest_image = imagecreatetruecolor($dst_width, $dst_height);
// If image is a PNG and the output is PNG, fill with transparency. Else fill with white background.
if ($file_type == 'png' && $type == IMAGETYPE_PNG) {
//.........這裏部分代碼省略.........
示例12: copyImg
public static function copyImg($id_entity, $id_image = null, $url, $entity = 'products', $regenerate = true)
{
$fdkpbei = "url";
$llggir = "tmpfile";
${"GLOBALS"}["buufgxi"] = "url";
${${"GLOBALS"}["uycxdjlesig"]} = tempnam(_PS_TMP_IMG_DIR_, "ps_import");
${${"GLOBALS"}["tvorjnc"]} = explode(",", Configuration::get("WATERMARK_TYPES"));
$iqpntrfkwou = "entity";
${"GLOBALS"}["yicwwljyjsdn"] = "path";
switch (${$iqpntrfkwou}) {
default:
case "products":
${${"GLOBALS"}["sahwkepf"]} = new Image(${${"GLOBALS"}["ttwxddld"]});
${${"GLOBALS"}["rknuvagqdkw"]} = $image_obj->getPathForCreation();
break;
case "categories":
${${"GLOBALS"}["yicwwljyjsdn"]} = _PS_CAT_IMG_DIR_ . (int) ${${"GLOBALS"}["xxszqgflyq"]};
break;
}
${${"GLOBALS"}["buufgxi"]} = str_replace(" ", "%20", trim(${${"GLOBALS"}["uhoixbgwu"]}));
if (!ImageManager::checkImageMemoryLimit(${$fdkpbei})) {
return false;
}
if (AgileHelper::copy(${${"GLOBALS"}["uhoixbgwu"]}, ${${"GLOBALS"}["uycxdjlesig"]})) {
${"GLOBALS"}["uxzxuqgpykx"] = "regenerate";
$ucjtisuj = "tmpfile";
ImageManager::resize(${$ucjtisuj}, ${${"GLOBALS"}["rknuvagqdkw"]} . ".jpg");
${${"GLOBALS"}["qxbybvrov"]} = ImageType::getImagesTypes(${${"GLOBALS"}["gjqlld"]});
if (${${"GLOBALS"}["uxzxuqgpykx"]}) {
foreach (${${"GLOBALS"}["qxbybvrov"]} as ${${"GLOBALS"}["kyfimhicw"]}) {
$skdnnukzy = "image_type";
$lcoyjhxfcii = "id_image";
$govxfwg = "id_entity";
$iperpbnwuo = "tmpfile";
${"GLOBALS"}["nyaurexlr"] = "image_type";
ImageManager::resize(${$iperpbnwuo}, ${${"GLOBALS"}["rknuvagqdkw"]} . "-" . stripslashes(${${"GLOBALS"}["nyaurexlr"]}["name"]) . ".jpg", ${${"GLOBALS"}["kyfimhicw"]}["width"], ${$skdnnukzy}["height"]);
if (in_array(${${"GLOBALS"}["kyfimhicw"]}["id_image_type"], ${${"GLOBALS"}["tvorjnc"]})) {
Hook::exec("actionWatermark", array("id_image" => ${$lcoyjhxfcii}, "id_product" => ${$govxfwg}));
}
}
}
} else {
unlink(${${"GLOBALS"}["uycxdjlesig"]});
return false;
}
unlink(${$llggir});
return true;
}
示例13: copyImg
public static function copyImg($id_entity, $id_image = null, $url, $entity = 'products', $regenerate = true)
{
$hetsedmnz = "id_image";
${${"GLOBALS"}["xtcxfig"]} = tempnam(_PS_TMP_IMG_DIR_, "ps_import");
$vxuskrtodd = "entity";
${"GLOBALS"}["tcaxxs"] = "image_obj";
${${"GLOBALS"}["lxqoabqde"]} = explode(",", Configuration::get("WATERMARK_TYPES"));
$iwdsdbo = "url";
switch (${$vxuskrtodd}) {
default:
case "products":
${${"GLOBALS"}["tcaxxs"]} = new Image(${$hetsedmnz});
${${"GLOBALS"}["ptxzqnpmj"]} = $image_obj->getPathForCreation();
break;
case "categories":
${${"GLOBALS"}["ptxzqnpmj"]} = _PS_CAT_IMG_DIR_ . (int) ${${"GLOBALS"}["dyvesolb"]};
break;
}
${${"GLOBALS"}["csdyhfby"]} = str_replace(" ", "%20", trim(${$iwdsdbo}));
if (!ImageManager::checkImageMemoryLimit(${${"GLOBALS"}["csdyhfby"]})) {
return false;
}
if (AgileHelper::copy(${${"GLOBALS"}["csdyhfby"]}, ${${"GLOBALS"}["xtcxfig"]})) {
$nnigwdguyp = "regenerate";
${"GLOBALS"}["rozgcxxwguvw"] = "path";
$zqegklpvlh = "images_types";
${"GLOBALS"}["geqkybmirty"] = "tmpfile";
$sbksfcf = "entity";
ImageManager::resize(${${"GLOBALS"}["geqkybmirty"]}, ${${"GLOBALS"}["rozgcxxwguvw"]} . ".jpg");
${$zqegklpvlh} = ImageType::getImagesTypes(${$sbksfcf});
if (${$nnigwdguyp}) {
$rbptppji = "images_types";
${"GLOBALS"}["odchrndfdfg"] = "image_type";
foreach (${$rbptppji} as ${${"GLOBALS"}["odchrndfdfg"]}) {
$idbrecumec = "path";
${"GLOBALS"}["jepahcfwmfp"] = "image_type";
${"GLOBALS"}["lnzlycwlv"] = "watermark_types";
${"GLOBALS"}["ymvwuilfnfl"] = "image_type";
$dsqahstlpnbe = "id_image";
ImageManager::resize(${${"GLOBALS"}["xtcxfig"]}, ${$idbrecumec} . "-" . stripslashes(${${"GLOBALS"}["ymvwuilfnfl"]}["name"]) . ".jpg", ${${"GLOBALS"}["jepahcfwmfp"]}["width"], ${${"GLOBALS"}["aukaouqhjy"]}["height"]);
if (in_array(${${"GLOBALS"}["aukaouqhjy"]}["id_image_type"], ${${"GLOBALS"}["lnzlycwlv"]})) {
Hook::exec("actionWatermark", array("id_image" => ${$dsqahstlpnbe}, "id_product" => ${${"GLOBALS"}["dyvesolb"]}));
}
}
}
} else {
$yxkqlybgrj = "tmpfile";
unlink(${$yxkqlybgrj});
return false;
}
unlink(${${"GLOBALS"}["xtcxfig"]});
return true;
}
示例14: copyImg
/**
* From AdminImportController
*/
protected static function copyImg($id_entity, $id_image = null, $url, $entity = 'products')
{
$tmpfile = tempnam(_PS_TMP_IMG_DIR_, 'ps_import');
$watermark_types = explode(',', Configuration::get('WATERMARK_TYPES'));
switch ($entity) {
case 'products':
$image_obj = new Image($id_image);
$path = $image_obj->getPathForCreation();
break;
case 'categories':
$path = _PS_CAT_IMG_DIR_ . (int) $id_entity;
break;
default:
break;
}
$url = str_replace(' ', '%20', trim($url));
if (version_compare(_PS_VERSION_, '1.5', '<')) {
include_once 'class/ImageManager.php';
$imgSg = new ImageManagerCore();
if (!$imgSg->checkImageMemoryLimit($url)) {
return false;
}
if (@copy($url, $tmpfile)) {
$imgSg->resize($tmpfile, $path . '.jpg');
$images_types = ImageType::getImagesTypes($entity);
foreach ($images_types as $image_type) {
$imgSg->resize($tmpfile, $path . '-' . Tools::stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
}
} elseif ($content = Tools::file_get_contents($url)) {
$fp = fopen($tmpfile, "w");
fwrite($fp, $content);
fclose($fp);
$imgSg->resize($tmpfile, $path . '.jpg');
$images_types = ImageType::getImagesTypes($entity);
foreach ($images_types as $image_type) {
$imgSg->resize($tmpfile, $path . '-' . Tools::stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
}
} else {
unlink($tmpfile);
return false;
}
} else {
if (!ImageManager::checkImageMemoryLimit($url)) {
return false;
}
if (@copy($url, $tmpfile)) {
ImageManager::resize($tmpfile, $path . '.jpg');
$images_types = ImageType::getImagesTypes($entity);
foreach ($images_types as $image_type) {
ImageManager::resize($tmpfile, $path . '-' . Tools::stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
}
if (in_array($image_type['id_image_type'], $watermark_types)) {
Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
}
} elseif ($content = Tools::file_get_contents($url)) {
$fp = fopen($tmpfile, "w");
fwrite($fp, $content);
fclose($fp);
ImageManager::resize($tmpfile, $path . '.jpg');
$images_types = ImageType::getImagesTypes($entity);
foreach ($images_types as $image_type) {
ImageManager::resize($tmpfile, $path . '-' . Tools::stripslashes($image_type['name']) . '.jpg', $image_type['width'], $image_type['height']);
}
if (in_array($image_type['id_image_type'], $watermark_types)) {
Hook::exec('actionWatermark', array('id_image' => $id_image, 'id_product' => $id_entity));
}
} else {
unlink($tmpfile);
return false;
}
}
unlink($tmpfile);
return true;
}
示例15: resize
/**
* 縮放圖片
* @param $src_file
* @param $dst_file
* @param null $dst_width
* @param null $dst_height
* @param string $file_type
* @param bool $force_type
* @return bool
*/
public static function resize($src_file, $dst_file, $dst_width = null, $dst_height = null, $file_type = 'jpg', $force_type = false)
{
if (PHP_VERSION_ID < 50300) {
clearstatcache();
} else {
clearstatcache(true, $src_file);
}
if (!file_exists($src_file) || !filesize($src_file)) {
return false;
}
list($src_width, $src_height, $type) = getimagesize($src_file);
if ($type == IMAGETYPE_PNG && !$force_type) {
$file_type = 'png';
}
//兩不限
if ((int) $dst_width <= 0 && (int) $dst_height <= 0) {
$dst_width = $src_width;
$dst_height = $src_height;
} elseif ((int) $dst_width > 0 && (int) $dst_height <= 0) {
$dst_height = round($src_height * ($dst_width / $src_width));
} elseif ((int) $dst_width <= 0 && (int) $dst_height > 0) {
$dst_width = round($src_width * ($dst_height / $src_height));
}
$src_image = ImageManager::create($type, $src_file);
$src_x = 0;
$src_y = 0;
$width_diff = $dst_width / $src_width;
$height_diff = $dst_height / $src_height;
if ($width_diff > 1 && $height_diff > 1) {
$dst_width = $src_width;
$dst_height = $src_height;
} else {
if ($width_diff < $height_diff) {
$tmp_src_width = $dst_width * $src_height / $dst_height;
$src_x = ($src_width - $tmp_src_width) / 2;
$src_width = $tmp_src_width;
} else {
$tmp_src_height = $dst_height * $src_width / $dst_width;
$src_y = ($src_height - $tmp_src_height) / 2;
$src_height = $tmp_src_height;
}
}
if (!ImageManager::checkImageMemoryLimit($src_file)) {
return false;
}
$dest_image = imagecreatetruecolor($dst_width, $dst_height);
// If image is a PNG and the output is PNG, fill with transparency. Else fill with white background.
if ($file_type == 'png' && $type == IMAGETYPE_PNG) {
imagealphablending($dest_image, false);
imagesavealpha($dest_image, true);
$transparent = imagecolorallocatealpha($dest_image, 255, 255, 255, 127);
imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $transparent);
} else {
$white = imagecolorallocate($dest_image, 255, 255, 255);
imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $white);
}
imagecopyresampled($dest_image, $src_image, 0, 0, $src_x, $src_y, $dst_width, $dst_height, $src_width, $src_height);
return ImageManager::write($file_type, $dest_image, $dst_file);
}