本文整理匯總了PHP中ImageManager::resize方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageManager::resize方法的具體用法?PHP ImageManager::resize怎麽用?PHP ImageManager::resize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ImageManager
的用法示例。
在下文中一共展示了ImageManager::resize方法的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);
}
}
// 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" />';
}
}
示例2: renderContent
/**
*
*/
public function renderContent($setting)
{
$t = array('name' => '', 'image' => '', 'imagesize' => '', 'alignment' => '', 'animation' => '', 'ispopup' => '1', 'imageurl' => '');
$protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://';
$url = Tools::htmlentitiesutf8($protocol . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__);
$setting = array_merge($t, $setting);
$size = explode('x', $setting['size']);
$setting['thumbnailurl'] = _PAGEBUILDER_IMAGE_URL_ . $setting['imagefile'];
$setting['imageurl'] = _PAGEBUILDER_IMAGE_URL_ . $setting['imagefile'];
if (count($size) == 2) {
$cache = _PS_CACHE_DIR_ . 'pspagebuilder/';
if (!file_exists($cache . $setting['imagefile'])) {
if (!is_dir($cache)) {
mkdir($cache, 0755);
}
if (ImageManager::resize(_PAGEBUILDER_IMAGE_DIR_ . $setting['imagefile'], $cache . $setting['imagefile'], $size[0], $size[1])) {
$setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $setting['imagefile'];
}
} else {
$setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $setting['imagefile'];
}
}
$output = array('type' => 'image', 'data' => $setting);
return $output;
}
示例3: afterImageUpload
protected function afterImageUpload()
{
/* Generate image with differents size */
if (!($obj = $this->loadObject(true))) {
return;
}
if ($obj->id && (isset($_FILES['image']) || isset($_FILES['thumb']))) {
$base_img_path = _PS_SCENE_IMG_DIR_ . $obj->id . '.jpg';
$images_types = ImageType::getImagesTypes('scenes');
foreach ($images_types as $k => $image_type) {
if ($image_type['name'] == 'scene_default' && isset($_FILES['image'])) {
ImageManager::resize($base_img_path, _PS_SCENE_IMG_DIR_ . $obj->id . '-' . stripslashes($image_type['name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
} else {
if ($image_type['name'] == 'm_scene_default') {
if (isset($_FILES['thumb']) && !$_FILES['thumb']['error']) {
$base_thumb_path = _PS_SCENE_THUMB_IMG_DIR_ . $obj->id . '.jpg';
} else {
$base_thumb_path = $base_img_path;
}
ImageManager::resize($base_thumb_path, _PS_SCENE_THUMB_IMG_DIR_ . $obj->id . '-' . stripslashes($image_type['name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
}
}
}
}
return true;
}
示例4: renderContent
/**
*
*/
public function renderContent($setting)
{
$t = array('name' => '', 'image' => '', 'imagesize' => '80x80', 'alignment' => '', 'animation' => '', 'ispopup' => '1', 'imageurl' => '', 'icon' => '', 'widget_heading' => '', 'icon_position' => 'left');
$protocol = !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443 ? 'https://' : 'http://';
$url = Tools::htmlentitiesutf8($protocol . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__);
$setting = array_merge($t, $setting);
$size = explode('x', $setting['imagesize']);
//$setting['thumbnailurl'] = $url.'modules/pspagebuilder/images/'.$setting['imagefile'];
//$setting['imageurl'] = $url.'modules/pspagebuilder/images/'.$setting['imagefile'];
$setting['thumbnailurl'] = '';
$setting['imageurl'] = '';
if (count($size) == 2 && empty($setting['icon'])) {
$cache = _PS_CACHE_DIR_ . 'pspagebuilder/';
if (!file_exists($cache . $setting['imagefile'])) {
if (!is_dir($cache)) {
mkdir($cache, 0777);
}
if (ImageManager::resize(_PAGEBUILDER_IMAGE_DIR_ . $setting['imagefile'], $cache . $setting['imagefile'], $size[0], $size[1])) {
$setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $setting['imagefile'];
}
} else {
$setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $setting['imagefile'];
}
}
$setting['content'] = $this->getValueByLang($setting, 'content');
$output = array('type' => 'ourservice', 'data' => $setting);
return $output;
}
示例5: postProcess
protected function postProcess()
{
$errors = '';
if (Tools::isSubmit('deleteImage')) {
if (!file_exists(dirname(__FILE__) . '/img/' . $this->_getUserImg())) {
$errors .= $this->displayError($this->l('This action cannot be taken.'));
} else {
unlink(dirname(__FILE__) . '/img/' . $this->_getUserImg());
Tools::redirectAdmin('index.php?tab=AdminModules&conf=4&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id));
}
}
if (Tools::isSubmit('submitUpdateScrolltop')) {
if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {
if ($error = ImageManager::validateUpload($_FILES['image'])) {
$errors .= $this->displayError($error);
} elseif (!ImageManager::resize($_FILES['image']['tmp_name'], dirname(__FILE__) . '/img/' . $this->_getUserImg())) {
$errors .= $this->displayError($this->l('An error occurred during the image upload.'));
}
}
foreach ($this->_scrollParams as $param => $value) {
if ($val = (int) Tools::getValue($param)) {
$this->_setScrollParam($param, $val);
} else {
$errors .= $this->displayError($this->l('"' . $param . '" is not valid.'));
}
}
if (!$errors) {
Tools::redirectAdmin('index.php?tab=AdminModules&conf=4&configure=' . $this->name . '&token=' . Tools::getAdminToken('AdminModules' . (int) Tab::getIdFromClassName('AdminModules') . (int) $this->context->employee->id));
}
}
$this->_html .= $errors;
}
示例6: thumbnail
/**
* 生成縮略圖
* @param $image
* @param $cache_image
* @param $size
* @param string $image_type
* @return bool|string
*/
public static function thumbnail($image, $cache_image, $size, $image_type = 'jpg')
{
if (!file_exists($image)) {
return '';
}
if (!file_exists(IMAGE_CACHE_DIR . $cache_image)) {
$infos = getimagesize($image);
if (!ImageManager::checkImageMemoryLimit($image)) {
return false;
}
$x = $infos[0];
$y = $infos[1];
$max_x = $size * 3;
if ($y < $size && $x <= $max_x) {
copy($image, IMAGE_CACHE_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, IMAGE_CACHE_DIR . $cache_image, $ratio_x, $size, $image_type);
}
}
return IMAGE_CACHE_DIR . $cache_image;
}
示例7: 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" />';
}
示例8: 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)));
}
}
示例9: uploadMainImage
public function uploadMainImage($image, $hotel_id, $hotel_img_path, $active = false)
{
if (isset($image)) {
if ($image['size'] > 0) {
$rand_name = $this->randomImageName();
Db::getInstance()->insert('htl_image', array('id_hotel' => (int) $hotel_id, 'hotel_image_id' => pSQL($rand_name)));
$image_name = $rand_name . '.jpg';
ImageManager::resize($image['tmp_name'], $hotel_img_path . $image_name);
}
}
}
示例10: afterImageUpload
// );
return parent::renderForm();
}
protected function afterImageUpload()
{
$res = true;
/* Generate image with differents size */
if (($id_friend_data = (int) Tools::getValue('id_friend_data')) && isset($_FILES) && isset($_FILES) && count($_FILES) && $_FILES['image']['name'] != null && file_exists(_PS_MYFRIENDS_IMG_DIR_ . $id_friend_data . '.jpg')) {
$images_types = ImageType::getImagesTypes('products');
foreach ($images_types as $k => $image_type) {
$res &= ImageManager::resize(_PS_MYFRIENDS_IMG_DIR_ . $id_friend_data . '.jpg', _PS_MYFRIENDS_IMG_DIR_ . $id_friend_data . '-' . stripslashes($image_type['name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
}
}
if (!$res) {
$this->errors[] = Tools::displayError('Unable to resize one or more of your pictures.');
示例11: postProcess
public function postProcess()
{
if (Tools::isSubmit('submitOptionsconfiguration')) {
if ($_FILES['htl_header_image']['name']) {
$this->validateHotelHeaderImage($_FILES['htl_header_image']);
if (!count($this->errors)) {
$img_path = _PS_IMG_DIR_ . 'hotel_header_image.png';
if (ImageManager::resize($_FILES['htl_header_image']['tmp_name'], $img_path)) {
Configuration::updateValue('WK_HOTEL_HEADER_IMAGE', 'hotel_header_image.png');
} else {
$this->errors[] = Tools::displayError('Some error occured while uoploading image.Please try again.');
}
}
}
}
parent::postProcess();
}
示例12: renderImage
protected function renderImage($url, $image, $size)
{
$setting = array();
$setting['thumbnailurl'] = _PAGEBUILDER_IMAGE_URL_ . $image;
$setting['imageurl'] = _PAGEBUILDER_IMAGE_URL_ . $image;
if (count($size) == 2) {
$cache = _PS_CACHE_DIR_ . 'pspagebuilder/';
if (!file_exists($cache . $image)) {
if (!is_dir($cache)) {
mkdir($cache, 0755);
}
if (ImageManager::resize(_PAGEBUILDER_IMAGE_DIR_ . $image, $cache . $image, $size[0], $size[1])) {
$setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $image;
}
} else {
$setting['thumbnailurl'] = $url . 'cache/pspagebuilder/' . $image;
}
}
return $setting;
}
示例13: 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;
}
示例14: ImageGenerate
public static function ImageGenerate()
{
$get_blog_image = SmartBlogPost::getBlogImage();
$get_cate_image = BlogCategory::getCatImage();
$get_author_image = _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar.jpg';
$category_types = BlogImageType::GetImageAllType('Category');
$posts_types = BlogImageType::GetImageAllType('post');
$author_types = BlogImageType::GetImageAllType('Author');
foreach ($category_types as $image_type) {
foreach ($get_cate_image as $cat_img) {
$path = _PS_MODULE_DIR_ . 'smartblog/images/category/' . $cat_img['id_smart_blog_category'] . '.jpg';
ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/category/' . $cat_img['id_smart_blog_category'] . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
}
}
foreach ($posts_types as $image_type) {
foreach ($get_blog_image as $blog_img) {
$path = _PS_MODULE_DIR_ . 'smartblog/images/' . $blog_img['id_smart_blog_post'] . '.jpg';
ImageManager::resize($path, _PS_MODULE_DIR_ . 'smartblog/images/' . $blog_img['id_smart_blog_post'] . '-' . stripslashes($image_type['type_name']) . '.jpg', (int) $image_type['width'], (int) $image_type['height']);
}
}
foreach ($author_types as $author_type) {
ImageManager::resize($get_author_image, _PS_MODULE_DIR_ . 'smartblog/images/avatar/avatar-' . stripslashes($author_type['type_name']) . '.jpg', (int) $author_type['width'], (int) $author_type['height']);
}
}
示例15: _regenerateNewImagesOfOffers
protected function _regenerateNewImagesOfOffers($dir, $type)
{
$dir = '/home/towers/sites/aphrodinet/img/offers/';
if (!is_dir($dir)) {
return false;
}
$generate_hight_dpi_images = (bool) Configuration::get('PS_HIGHT_DPI');
include_once __DIR__ . '/../../../modules/aphrodinet/classes/AphOfferImage.php';
error_log(var_export(AphOfferImage::getAllImages(), true));
foreach (AphOfferImage::getAllImages() as $image) {
$imageObj = new AphOfferImage($image['id_image']);
$existing_img = $dir . $imageObj->getExistingImgPath() . '.jpg';
if (file_exists($existing_img) && filesize($existing_img)) {
foreach ($type as $imageType) {
unlink($dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg');
//if (!file_exists($dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg')) {
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) {
$this->errors[] = sprintf(Tools::displayError('Original image is corrupt (%s) for product ID %2$d or bad permission on folder'), $existing_img, (int) $imageObj->id_product);
}
if ($generate_hight_dpi_images) {
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) {
$this->errors[] = sprintf(Tools::displayError('Original image is corrupt (%s) for product ID %2$d or bad permission on folder'), $existing_img, (int) $imageObj->id_product);
}
}
//}
}
} else {
$this->errors[] = sprintf(Tools::displayError('Original image is missing or empty (%1$s) for product ID %2$d'), $existing_img, (int) $imageObj->id_product);
}
if (time() - $this->start_time > $this->max_execution_time - 4) {
// stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
return 'timeout';
}
}
return (bool) count($this->errors);
}