本文整理汇总了PHP中image_resize函数的典型用法代码示例。如果您正苦于以下问题:PHP image_resize函数的具体用法?PHP image_resize怎么用?PHP image_resize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了image_resize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _generate_attachment
/**
* Creates a cropped version of an image for a given attachment ID.
*
* @param int $attachment_id The attachment for which to generate a cropped image.
* @param int $width The width of the cropped image in pixels.
* @param int $height The height of the cropped image in pixels.
* @param bool $crop Whether to crop the generated image.
* @return string The full path to the cropped image. Empty if failed.
*/
private function _generate_attachment($attachment_id = 0, $width = 0, $height = 0, $crop = true)
{
$attachment_id = (int) $attachment_id;
$width = (int) $width;
$height = (int) $height;
$crop = (bool) $crop;
$original_path = get_attached_file($attachment_id);
// fix a WP bug up to 2.9.2
if (!function_exists('wp_load_image')) {
require_once ABSPATH . 'wp-admin/includes/image.php';
}
$resized_path = @image_resize($original_path, $width, $height, $crop);
if (!is_wp_error($resized_path) && !is_array($resized_path)) {
return $resized_path;
// perhaps this image already exists. If so, return it.
} else {
$orig_info = pathinfo($original_path);
$suffix = "{$width}x{$height}";
$dir = $orig_info['dirname'];
$ext = $orig_info['extension'];
$name = basename($original_path, ".{$ext}");
$destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
if (file_exists($destfilename)) {
return $destfilename;
}
}
return '';
}
示例2: file_processValue
function file_processValue($Value, $Type, $Field, $Config, $EID)
{
if (!empty($Value)) {
//dump($Value);
//dump($Type);
//dump($Field);
//dump($Config);
//die;
switch ($Type) {
case 'image':
$Value = strtok($Value, '?');
$imageWidth = $Config['_ImageSizeX'][$Field] == 'auto' ? '100' : $Config['_ImageSizeX'][$Field];
$imageHeight = $Config['_ImageSizeY'][$Field] == 'auto' ? '100' : $Config['_ImageSizeY'][$Field];
$iconWidth = $Config['_IconSizeX'][$Field] == 'auto' ? '100' : $Config['_IconSizeX'][$Field];
$iconHeight = $Config['_IconSizeY'][$Field] == 'auto' ? '100' : $Config['_IconSizeY'][$Field];
$uploadVars = wp_upload_dir();
$SourceFile = str_replace($uploadVars['baseurl'], $uploadVars['basedir'], $Value);
if (!file_exists($SourceFile)) {
return 'Image does not exists.';
}
$dim = getimagesize($SourceFile);
$newDim = image_resize_dimensions($dim[0], $dim[1], $iconWidth, $iconHeight, true);
if (!empty($newDim)) {
$Sourcepath = pathinfo($SourceFile);
$URLpath = pathinfo($Value);
$iconURL = $URLpath['dirname'] . '/' . $URLpath['filename'] . '-' . $newDim[4] . 'x' . $newDim[5] . '.' . $URLpath['extension'];
if (!file_exists($Sourcepath['dirname'] . '/' . $Sourcepath['filename'] . '-' . $newDim[4] . 'x' . $newDim[5] . '.' . $Sourcepath['extension'])) {
$image = image_resize($SourceFile, $imageWidth, $imageHeight, true);
$icon = image_resize($SourceFile, $iconWidth, $iconHeight, true);
}
} else {
$iconURL = $Value;
$iconWidth = $dim[0];
$iconHeight = $dim[1];
}
$ClassName = '';
if (!empty($Config['_ImageClassName'][$Field])) {
$ClassName = 'class="' . $Config['_ImageClassName'][$Field] . '" ';
}
if (!empty($Config['_IconURLOnly'][$Field])) {
return $iconURL;
}
return '<img src="' . $iconURL . '" ' . $ClassName . image_hwstring($iconWidth, $iconHeight) . '>';
break;
case 'mp3':
$File = explode('?', $Value);
$UniID = uniqid($EID . '_');
//$ReturnData = '<span id="'.$UniID.'">'.$File[1].'</span>';
$ReturnData = '<audio id="' . $UniID . '" src="' . $File[0] . '">unavailable</audio>';
$_SESSION['dataform']['OutScripts'] .= "\n\t\t\t\t\tAudioPlayer.embed(\"" . $UniID . "\", {\n\t\t\t\t\t";
if (!empty($Config['_PlayerCFG']['Autoplay'][$Field])) {
$_SESSION['dataform']['OutScripts'] .= " autostart: 'yes', ";
}
if (!empty($Config['_PlayerCFG']['Animation'][$Field])) {
$_SESSION['dataform']['OutScripts'] .= " animation: 'yes', ";
}
$_SESSION['dataform']['OutScripts'] .= "\n transparentpagebg: 'yes',\n\t\t\t\t\t\tsoundFile: \"" . $File[0] . "\",\n\t\t\t\t\t\ttitles: \"" . $File[1] . "\"\n\t\t\t\t\t});\n\n\t\t\t\t";
$_SESSION['dataform']['OutScripts'] .= "\n jQuery(document).ready(function(\$) {\n AudioPlayer.setup(\"" . WP_PLUGIN_URL . "/db-toolkit/data_form/fieldtypes/file/player.swf\", {\n width: '100%',\n initialvolume: 100,\n transparentpagebg: \"yes\",\n left: \"000000\",\n lefticon: \"FFFFFF\"\n });\n });";
return $ReturnData;
break;
case 'file':
case 'multi':
if (empty($Config['_fileReturnValue'][$Field])) {
$Config['_fileReturnValue'][$Field] = 'iconlink';
}
$pathInfo = pathinfo($Value);
$s3Enabled = false;
$prime = $Field;
if (!empty($Config['_CloneField'][$Field]['Master'])) {
$prime = $Config['_CloneField'][$Field]['Master'];
}
if (!empty($Config['_enableS3'][$prime]) && !empty($Config['_AWSAccessKey'][$prime]) && !empty($Config['_AWSSecretKey'][$prime])) {
include_once DB_TOOLKIT . 'data_form/fieldtypes/file/s3.php';
$s3 = new S3($Config['_AWSAccessKey'][$prime], $Config['_AWSSecretKey'][$prime]);
$s3Enabled = true;
}
switch ($Config['_fileReturnValue'][$Field]) {
case 'iconlink':
if (empty($Value)) {
return 'no file uploaded';
}
if (!empty($Config['_enableS3'][$prime]) && !empty($Config['_AWSAccessKey'][$prime]) && !empty($Config['_AWSSecretKey'][$prime])) {
$File = 'http://' . $Config['_AWSBucket'][$prime] . '.s3.amazonaws.com/' . $Value;
} else {
$File = $Value;
}
$Dets = pathinfo($File);
$ext = strtolower($Dets['extension']);
if (file_exists(WP_PLUGIN_DIR . '/db-toolkit/data_form/fieldtypes/file/icons/' . $ext . '.gif')) {
$Icon = '<img src="' . WP_PLUGIN_URL . '/db-toolkit/data_form/fieldtypes/file/icons/' . $ext . '.gif" align="absmiddle" /> ';
} else {
$Icon = '<img src="' . WP_PLUGIN_URL . '/db-toolkit/data_form/fieldtypes/file/icons/file.gif" align="absmiddle" /> ';
}
return '<a href="' . $File . '">' . $Icon . ' ' . basename($File) . '</a>';
break;
case 'filesize':
if (!empty($s3Enabled)) {
$object = $s3->getObjectInfo($Config['_AWSBucket'][$prime], $Value);
return file_return_bytes($object['size']);
} else {
//.........这里部分代码省略.........
示例3: get_image_url
/**
* Retrieve resized image URL
*
* @param int $id Post ID or Attachment ID
* @param int $width desired width of image (optional)
* @param int $height desired height of image (optional)
* @return string URL
* @author Shane & Peter, Inc. (Peter Chester)
*/
function get_image_url($id, $width = false, $height = false)
{
/**/
// Get attachment and resize but return attachment path (needs to return url)
$attachment = wp_get_attachment_metadata($id);
$attachment_url = wp_get_attachment_url($id);
if (isset($attachment_url)) {
if ($width && $height) {
$uploads = wp_upload_dir();
$imgpath = $uploads['basedir'] . '/' . $attachment['file'];
error_log($imgpath);
$image = image_resize($imgpath, $width, $height);
if ($image && !is_wp_error($image)) {
error_log(is_wp_error($image));
$image = path_join(dirname($attachment_url), basename($image));
} else {
$image = $attachment_url;
}
} else {
$image = $attachment_url;
}
if (isset($image)) {
return $image;
}
}
}
示例4: prepare_image
function prepare_image($url, $x, $y)
{
$wpcurl = strlen(WP_CONTENT_URL);
if (substr($url, 0, $wpcurl) != WP_CONTENT_URL) {
return $url;
} else {
$path = WP_CONTENT_DIR . substr($url, $wpcurl);
if (!file_exists($path)) {
return $url;
} else {
$new_path = strlen($path) - 1 - strlen(end(explode(".", $path)));
$new_path = substr($path, 0, $new_path) . "-" . $x . "x" . $y . "." . end(explode(".", $path));
if (!file_exists($new_path)) {
require_once ABSPATH . 'wp-admin/includes/image.php';
$img = image_resize($path, $x, $y, true);
if (!is_string($img)) {
return $url;
} else {
return trailingslashit(dirname($url)) . basename($img);
}
} else {
$new_url = strlen($url) - 1 - strlen(end(explode(".", $url)));
return substr($url, 0, $new_url) . "-" . $x . "x" . $y . "." . end(explode(".", $url));
}
}
}
}
示例5: aq_resize
/**
* Title : Aqua Resizer
* Description : Resizes WordPress images on the fly
* Version : 1.1.5
* Author : Syamil MJ
* Author URI : http://aquagraphite.com
* License : WTFPL - http://sam.zoy.org/wtfpl/
* Documentation : https://github.com/sy4mil/Aqua-Resizer/
*
* @param string $url - (required) must be uploaded using wp media uploader
* @param int $width - (required)
* @param int $height - (optional)
* @param bool $crop - (optional) default to soft crop
* @param bool $single - (optional) returns an array if false
* @uses wp_upload_dir()
* @uses image_resize_dimensions()
* @uses image_resize()
*
* @return str|array
*/
function aq_resize($url, $width, $height = null, $crop = null, $single = true)
{
//validate inputs
if (!$url or !$width) {
return false;
}
//define upload path & dir
$upload_info = wp_upload_dir();
$upload_dir = $upload_info['basedir'];
$upload_url = $upload_info['baseurl'];
//check if $img_url is local
if (strpos($url, $upload_url) === false) {
return false;
}
//define path of image
$rel_path = str_replace($upload_url, '', $url);
$img_path = $upload_dir . $rel_path;
//check if img path exists, and is an image indeed
if (!file_exists($img_path) or !getimagesize($img_path)) {
return false;
}
//get image info
$info = pathinfo($img_path);
$ext = $info['extension'];
list($orig_w, $orig_h) = getimagesize($img_path);
//get image size after cropping
$dims = image_resize_dimensions($orig_w, $orig_h, $width, $height, $crop);
$dst_w = $dims[4];
$dst_h = $dims[5];
//use this to check if cropped image already exists, so we can return that instead
$suffix = "{$dst_w}x{$dst_h}";
$dst_rel_path = str_replace('.' . $ext, '', $rel_path);
$destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}";
if (!$dst_h) {
//can't resize, so return original url
$img_url = $url;
$dst_w = $orig_w;
$dst_h = $orig_h;
} elseif (file_exists($destfilename) && getimagesize($destfilename)) {
$img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}";
} else {
$resized_img_path = image_resize($img_path, $width, $height, $crop);
if (!is_wp_error($resized_img_path)) {
$resized_rel_path = str_replace($upload_dir, '', $resized_img_path);
$img_url = $upload_url . $resized_rel_path;
} else {
return false;
}
}
//return the output
if ($single) {
//str return
$image = $img_url;
} else {
//array return
$image = array(0 => $img_url, 1 => $dst_w, 2 => $dst_h);
}
return $image;
}
示例6: index
public function index()
{
if ($this->config->get('google_base_status')) {
$output = '<?xml version="1.0" encoding="UTF-8" ?>';
$output .= '<rss version="2.0" xmlns:g="http://base.google.com/ns/1.0">';
$output .= '<channel>';
$output .= '<title>' . $this->config->get('config_store') . '</title>';
$output .= '<description>' . $this->config->get('config_meta_description') . '</description>';
$output .= '<link>' . HTTP_SERVER . '</link>';
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->helper('image');
$products = $this->model_catalog_product->getProducts();
foreach ($products as $product) {
if ($product['description']) {
$output .= '<item>';
$output .= '<title>' . $product['name'] . '</title>';
$output .= '<g:brand>' . $product['manufacturer'] . '</g:brand>';
$output .= '<g:condition>new</g:condition>';
$output .= '<description>' . $product['description'] . '</description>';
$output .= '<guid>' . $product['product_id'] . '</guid>';
if ($product['image']) {
$output .= '<g:image_link>' . image_resize($product['image'], 500, 500) . '</g:image_link>';
} else {
$output .= '<g:image_link>' . image_resize('no_image.jpg', 500, 500) . '</g:image_link>';
}
$output .= '<link>' . $this->url->http('product/product&product_id=' . $product['product_id']) . '</link>';
$output .= '<g:mpn>' . $product['model'] . '</g:mpn>';
$output .= '<g:price>' . $this->tax->calculate($product['price'], $product['tax_class_id']) . '</g:price>';
$categories = $this->model_catalog_product->getCategories($product['product_id']);
foreach ($categories as $category) {
$path = $this->getPath($category['category_id']);
if ($path) {
$string = '';
foreach (explode('_', $path) as $path_id) {
$category_info = $this->model_catalog_category->getCategory($path_id);
if ($category_info) {
if (!$string) {
$string = $category_info['name'];
} else {
$string .= ' > ' . $category_info['name'];
}
}
}
$output .= '<g:product_type>' . $string . '</g:product_type>';
}
}
$output .= '<g:quantity>' . $product['quantity'] . '</g:quantity>';
$output .= '<g:upc>' . $product['model'] . '</g:upc>';
$output .= '<g:weight>' . $this->weight->format($product['weight'], $product['weight_class_id']) . '</g:weight>';
$output .= '</item>';
}
}
$output .= '</channel>';
$output .= '</rss>';
$this->response->addHeader('Content-Type', 'application/rss+xml');
$this->response->setOutput($output);
}
}
示例7: wp_create_thumbnail
/**
* Create a thumbnail from an Image given a maximum side size.
*
* This function can handle most image file formats which PHP supports. If PHP
* does not have the functionality to save in a file of the same format, the
* thumbnail will be created as a jpeg.
*
* @since 1.2.0
*
* @param mixed $file Filename of the original image, Or attachment id.
* @param int $max_side Maximum length of a single side for the thumbnail.
* @param mixed $deprecated Never used.
* @return string Thumbnail path on success, Error string on failure.
*/
function wp_create_thumbnail($file, $max_side, $deprecated = '')
{
if (!empty($deprecated)) {
_deprecated_argument(__FUNCTION__, '1.2');
}
$thumbpath = image_resize($file, $max_side, $max_side);
return apply_filters('wp_create_thumbnail', $thumbpath);
}
示例8: vt_resize
function vt_resize($attach_id = null, $img_url = null, $width, $height, $crop = false)
{
// this is an attachment, so we have the ID
if ($attach_id) {
$image_src = wp_get_attachment_image_src($attach_id, 'full');
$file_path = get_attached_file($attach_id);
// this is not an attachment, let's use the image url
} else {
if ($img_url) {
$file_path = parse_url($img_url);
$file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
//$file_path = ltrim( $file_path['path'], '/' );
//$file_path = rtrim( ABSPATH, '/' ).$file_path['path'];
$orig_size = getimagesize($file_path);
$image_src[0] = $img_url;
$image_src[1] = $orig_size[0];
$image_src[2] = $orig_size[1];
}
}
$file_info = pathinfo($file_path);
$extension = '.' . $file_info['extension'];
// the image path without the extension
$no_ext_path = $file_info['dirname'] . '/' . $file_info['filename'];
$cropped_img_path = $no_ext_path . '-' . $width . 'x' . $height . $extension;
// checking if the file size is larger than the target size
// if it is smaller or the same size, stop right here and return
if ($image_src[1] > $width || $image_src[2] > $height) {
// the file is larger, check if the resized version already exists (for $crop = true but will also work for $crop = false if the sizes match)
if (file_exists($cropped_img_path)) {
$cropped_img_url = str_replace(basename($image_src[0]), basename($cropped_img_path), $image_src[0]);
$vt_image = array('url' => $cropped_img_url, 'width' => $width, 'height' => $height);
return $vt_image;
}
// $crop = false
if ($crop == false) {
// calculate the size proportionaly
$proportional_size = wp_constrain_dimensions($image_src[1], $image_src[2], $width, $height);
$resized_img_path = $no_ext_path . '-' . $proportional_size[0] . 'x' . $proportional_size[1] . $extension;
// checking if the file already exists
if (file_exists($resized_img_path)) {
$resized_img_url = str_replace(basename($image_src[0]), basename($resized_img_path), $image_src[0]);
$vt_image = array('url' => $resized_img_url, 'width' => $proportional_size[0], 'height' => $proportional_size[1]);
return $vt_image;
}
}
// no cache files - let's finally resize it
$new_img_path = image_resize($file_path, $width, $height, $crop);
$new_img_size = getimagesize($new_img_path);
$new_img = str_replace(basename($image_src[0]), basename($new_img_path), $image_src[0]);
// resized output
$vt_image = array('url' => $new_img, 'width' => $new_img_size[0], 'height' => $new_img_size[1]);
return $vt_image;
}
// default output - without resizing
$vt_image = array('url' => $image_src[0], 'width' => $image_src[1], 'height' => $image_src[2]);
return $vt_image;
}
示例9: move_images
/**
* Image moving and resizing routine.
*
* Relies on WP built-in image resizing.
*
* @param array Image paths to move from temp directory
* @return mixed Array of new image paths, or (bool)false on failure.
* @access private
*/
function move_images($imgs)
{
if (!$imgs) {
return false;
}
if (!is_array($imgs)) {
$imgs = array($imgs);
}
global $bp;
$ret = array();
$thumb_w = get_option('thumbnail_size_w');
$thumb_w = $thumb_w ? $thumb_w : 100;
$thumb_h = get_option('thumbnail_size_h');
$thumb_h = $thumb_h ? $thumb_h : 100;
// Override thumbnail image size in wp-config.php
if (defined('BPFB_THUMBNAIL_IMAGE_SIZE')) {
list($tw, $th) = explode('x', BPFB_THUMBNAIL_IMAGE_SIZE);
$thumb_w = (int) $tw ? (int) $tw : $thumb_w;
$thumb_h = (int) $th ? (int) $th : $thumb_h;
}
$processed = 0;
foreach ($imgs as $img) {
$processed++;
if (BPFB_IMAGE_LIMIT && $processed > BPFB_IMAGE_LIMIT) {
break;
}
// Do not even bother to process more.
if (preg_match('!^https?:\\/\\/!i', $img)) {
// Just add remote images
$ret[] = $img;
continue;
}
$pfx = $bp->loggedin_user->id . '_' . preg_replace('/ /', '', microtime());
$tmp_img = realpath(BPFB_TEMP_IMAGE_DIR . $img);
$new_img = BPFB_BASE_IMAGE_DIR . "{$pfx}_{$img}";
if (@rename($tmp_img, $new_img)) {
if (function_exists('wp_get_image_editor')) {
// New way of resizing the image
$image = wp_get_image_editor($new_img);
if (!is_wp_error($image)) {
$thumb_filename = $image->generate_filename('bpfbt');
$image->resize($thumb_w, $thumb_h, false);
$image->save($thumb_filename);
}
} else {
// Old school fallback
image_resize($new_img, $thumb_w, $thumb_h, false, 'bpfbt');
}
$ret[] = pathinfo($new_img, PATHINFO_BASENAME);
} else {
return false;
}
}
return $ret;
}
示例10: index
public function index()
{
$this->language->load('common/home');
$this->document->title = $this->config->get('config_title');
$this->document->description = $this->config->get('config_meta_description');
$this->document->breadcrumbs = array();
$this->document->breadcrumbs[] = array('href' => $this->url->http('common/home'), 'text' => $this->language->get('text_home'), 'separator' => FALSE);
$this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store'));
$this->data['welcome'] = html_entity_decode($this->config->get('config_welcome_' . $this->language->getId()));
$this->data['text_latest'] = $this->language->get('text_latest');
$this->load->model('catalog/product');
$this->load->model('catalog/review');
$this->load->model('tool/seo_url');
$this->load->helper('image');
$this->data['products'] = array();
foreach ($this->model_catalog_product->getLatestProducts(8) as $result) {
if ($result['image']) {
$image = $result['image'];
} else {
$image = 'no_image.jpg';
}
$rating = $this->model_catalog_review->getAverageRating($result['product_id']);
$special = FALSE;
$discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
if ($discount) {
$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
if ($special) {
$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
}
}
$this->data['products'][] = array('name' => $result['name'], 'model' => $result['model'], 'rating' => $rating, 'stars' => sprintf($this->language->get('text_stars'), $rating), 'thumb' => image_resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')), 'price' => $price, 'special' => $special, 'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id'])));
}
if (!$this->config->get('config_customer_price')) {
$this->data['display_price'] = TRUE;
} elseif ($this->customer->isLogged()) {
$this->data['display_price'] = TRUE;
} else {
$this->data['display_price'] = FALSE;
}
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/home.tpl')) {
$this->template = $this->config->get('config_template') . '/template/common/home.tpl';
} else {
$this->template = 'default/template/common/home.tpl';
}
$this->children = array('common/header', 'common/footer', 'common/column_left', 'common/column_right');
$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
}
示例11: generate_overlayed_image
function generate_overlayed_image($string)
{
global $mtimgpath, $maxsize;
$result = image_new($maxsize, $maxsize);
$parts = explode('^', $string);
foreach ($parts as $part) {
if ($part != '' && $part[0] != '[') {
$overlay = imagecreatefrompng($mtimgpath . '/' . $part);
image_resize($overlay, $maxsize, $maxsize);
imagecopy($result, $overlay, 0, 0, 0, 0, imagesx($overlay), imagesy($overlay));
imagedestroy($overlay);
}
}
return $result;
}
示例12: imsanity_image_resize
/**
* Replacement for deprecated image_resize function
* @param string $file Image file path.
* @param int $max_w Maximum width to resize to.
* @param int $max_h Maximum height to resize to.
* @param bool $crop Optional. Whether to crop image or resize.
* @param string $suffix Optional. File suffix.
* @param string $dest_path Optional. New image file path.
* @param int $jpeg_quality Optional, default is 90. Image quality percentage.
* @return mixed WP_Error on failure. String with new destination path.
*/
function imsanity_image_resize($file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90)
{
if (function_exists('wp_get_image_editor')) {
// WP 3.5 and up use the image editor
$editor = wp_get_image_editor($file);
if (is_wp_error($editor)) {
return $editor;
}
$editor->set_quality($jpeg_quality);
// try to correct for auto-rotation if the info is available
if (function_exists('exif_read_data')) {
$exif = exif_read_data($file);
$orientation = is_array($exif) && array_key_exists('Orientation', $exif) ? $exif['Orientation'] : 0;
switch ($orientation) {
case 3:
$editor->rotate(180);
break;
case 6:
$editor->rotate(-90);
break;
case 8:
$editor->rotate(90);
break;
}
}
$resized = $editor->resize($max_w, $max_h, $crop);
if (is_wp_error($resized)) {
return $resized;
}
$dest_file = $editor->generate_filename($suffix, $dest_path);
// FIX: make sure that the destination file does not exist. this fixes
// an issue during bulk resize where one of the optimized media filenames may get
// used as the temporary file, which causes it to be deleted.
while (file_exists($dest_file)) {
$dest_file = $editor->generate_filename('TMP', $dest_path);
}
$saved = $editor->save($dest_file);
if (is_wp_error($saved)) {
return $saved;
}
return $dest_file;
} else {
// wordpress prior to 3.5 uses the old image_resize function
return image_resize($file, $max_w, $max_h, $crop, $suffix, $dest_path, $jpeg_quality);
}
}
示例13: index
protected function index()
{
$this->language->load('module/bestseller');
$this->data['heading_title'] = $this->language->get('heading_title');
$this->load->model('catalog/product');
$this->load->model('catalog/review');
$this->load->model('tool/seo_url');
$this->load->helper('image');
$this->data['products'] = array();
$results = $this->model_catalog_product->getBestSellerProducts($this->config->get('bestseller_limit'));
foreach ($results as $result) {
if ($result['image']) {
$image = $result['image'];
} else {
$image = 'no_image.jpg';
}
$rating = $this->model_catalog_review->getAverageRating($result['product_id']);
$special = FALSE;
$discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
if ($discount) {
$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
if ($special) {
$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
}
}
$this->data['products'][] = array('name' => $result['name'], 'price' => $price, 'special' => $special, 'image' => image_resize($image, 38, 38), 'href' => $this->model_tool_seo_url->rewrite($this->url->http('product/product&product_id=' . $result['product_id'])));
}
if (!$this->config->get('config_customer_price')) {
$this->data['display_price'] = TRUE;
} elseif ($this->customer->isLogged()) {
$this->data['display_price'] = TRUE;
} else {
$this->data['display_price'] = FALSE;
}
$this->id = 'bestseller';
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/bestseller.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/bestseller.tpl';
} else {
$this->template = 'default/template/module/bestseller.tpl';
}
$this->render();
}
示例14: validate
function validate($data = null)
{
$this->errors = array();
if (!empty($data)) {
$data = empty($data[$this->model]) ? $data : $data[$this->model];
foreach ($data as $dkey => $dval) {
$this->data->{$dkey} = stripslashes($dval);
}
extract($data, EXTR_SKIP);
if (empty($title)) {
$this->errors['title'] = __('Please fill in a title', $this->plugin_name);
}
if (empty($description)) {
$this->errors['description'] = __('Please fill in a description', $this->plugin_name);
}
if (empty($image_url)) {
$this->errors['image_url'] = __('Please specify an image', $this->plugin_name);
} else {
if ($image = wp_remote_fopen($image_url)) {
$filename = basename($image_url);
$filepath = ABSPATH . 'wp-content' . DS . 'uploads' . DS . $this->plugin_name . DS;
$filefull = $filepath . $filename;
if (!file_exists($filefull)) {
$fh = @fopen($filefull, "w");
@fwrite($fh, $image);
@fclose($fh);
$name = GalleryHtmlHelper::strip_ext($filename, 'filename');
$ext = GalleryHtmlHelper::strip_ext($filename, 'ext');
$thumbfull = $filepath . $name . '-thumb.' . $ext;
$smallfull = $filepath . $name . '-small.' . $ext;
image_resize($filefull, $width = null, $height = 75, $crop = false, $append = 'thumb', $dest = null, $quality = 100);
image_resize($filefull, $width = 50, $height = 50, $crop = true, $append = 'small', $dest = null, $quality = 100);
@chmod($filefull, 0777);
@chmod($thumbfull, 0777);
@chmod($smallfull, 0777);
}
}
}
} else {
$this->errors[] = __('No data was posted', $this->plugin_name);
}
return $this->errors;
}
示例15: ml_image_resize
function ml_image_resize($img_url, $width, $height, $crop = false, $jpeg_quality = 90)
{
$file_path = parse_url($img_url);
//$file_path = ltrim( $file_path['path'], '/' );
$file_path = rtrim(ABSPATH, '/') . $file_path['path'];
$orig_size = @getimagesize($file_path);
$image_src[0] = $img_url;
$image_src[1] = $orig_size[0];
$image_src[2] = $orig_size[1];
$file_info = pathinfo($file_path);
$extension = '.' . $file_info['extension'];
// the image path without the extension
$no_ext_path = $file_info['dirname'] . '/' . $file_info['filename'];
$cropped_img_path = $no_ext_path . '-' . $width . 'x' . $height . $extension;
// checking if the file size is larger than the target size
// if it is smaller or the same size, stop right here and return
if ($image_src[1] > $width || $image_src[2] > $height) {
// the file is larger, check if the resized version already exists (for crop = true but will also work for crop = false if the sizes match)
if (file_exists($cropped_img_path)) {
$cropped_img_url = str_replace(basename($image_src[0]), basename($cropped_img_path), $image_src[0]);
return $cropped_img_url;
}
// crop = false
if ($crop == false) {
// calculate the size proportionaly
$proportional_size = wp_constrain_dimensions($image_src[1], $image_src[2], $width, $height);
$resized_img_path = $no_ext_path . '-' . $proportional_size[0] . 'x' . $proportional_size[1] . $extension;
// checking if the file already exists
if (file_exists($resized_img_path)) {
$resized_img_url = str_replace(basename($image_src[0]), basename($resized_img_path), $image_src[0]);
return $resized_img_url;
}
}
// no cached files - let's finally resize it
$new_img_path = image_resize($file_path, $width, $height, $crop, NULL, $cropped_img_path, $jpeg_quality);
$new_img_size = @getimagesize($new_img_path);
$new_img = str_replace(basename($image_src[0]), basename($new_img_path), $image_src[0]);
// resized output
return $new_img;
}
return $image_src[0];
}