本文整理汇总了PHP中Image::resize方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::resize方法的具体用法?PHP Image::resize怎么用?PHP Image::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resize
public function resize($filename, $width, $height)
{
if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
return;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height);
$image->save(DIR_IMAGE . $new_image);
}
if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
return HTTPS_CATALOG . 'image/' . $new_image;
} else {
return HTTP_CATALOG . 'image/' . $new_image;
}
}
示例2: array
function admin_save()
{
if (isset($this->data) && !empty($this->data)) {
if (isset($this->data['Text']['id'])) {
$screenshot = $this->Screenshot->find('first', array('conditions' => array('Screenshot.id' => $this->data['Screenshot']['id'])));
}
// resize
App::import('Vendor', 'Image', array('file' => 'image.php'));
$Image = new Image();
if (empty($this->data['Screenshot']['image']['name'])) {
unset($this->data['Screenshot']['image']);
} else {
$ext = preg_replace('/(.*)(\\.(.*))$/', '\\3', $this->data['Screenshot']['image']['name']);
$imageName = md5(uniqid(mt_rand(), true)) . '.' . $ext;
move_uploaded_file($this->data['Screenshot']['image']['tmp_name'], WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'original' . DS . $imageName);
$Image->resize(WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'original' . DS . $imageName, WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'big' . DS . $imageName, 640, 480);
$Image->resize(WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'original' . DS . $imageName, WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'medium' . DS . $imageName, 350, 350);
$Image->resize(WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'original' . DS . $imageName, WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'small' . DS . $imageName, 100, 100);
$this->data['Screenshot']['image'] = $imageName;
if (isset($screenshot['Screenshot']['image']) && !empty($screenshot['Screenshot']['image'])) {
@unlink(WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'original' . DS . $screenshot['Screenshot']['image']);
@unlink(WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'small' . DS . $screenshot['Screenshot']['image']);
@unlink(WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'medium' . DS . $screenshot['Screenshot']['image']);
@unlink(WWW_ROOT . 'img' . DS . 'website' . DS . 'screenshots' . DS . 'big' . DS . $screenshot['Screenshot']['image']);
}
}
$this->Screenshot->save($this->data);
$this->redirect('/admin/screenshots');
} else {
$this->redirect('/admin/screenshots');
}
}
示例3: edit
public function edit($album_url, $photo)
{
$photo = new Photo_Model($album_url . '/' . $photo);
if (!$photo->id) {
Event::run('system.404');
}
$this->template->content = new View('admin/photo/form');
$this->template->content->errors = '';
$this->template->content->action = 'Edit';
if ($_POST) {
try {
$photo->set_fields($_POST);
if (!$_FILES['photo']['error']) {
// Delete the old photo before we change it
$photo->delete_file();
$photo->photo_filename = $_FILES['photo']['name'];
// Create a thumbnail and resized version
$image = new Image($_FILES['photo']['tmp_name']);
$image->resize(Kohana::config('photo_gallery.image_width'), Kohana::config('photo_gallery.image_height'), Image::AUTO);
$image->save(APPPATH . 'views/media/photos/' . $album_url . '/' . $_FILES['photo']['name']);
$image->resize(Kohana::config('photo_gallery.thumbnail_width'), Kohana::config('photo_gallery.thumbnail_height'), Image::AUTO);
$image->save(APPPATH . 'views/media/photos/' . $album_url . '/thumb_' . $_FILES['photo']['name']);
}
$photo->save();
url::redirect('album/view/' . $photo->album->url_name);
} catch (Kohana_User_Exception $e) {
$this->template->content->errors = $e;
}
}
$this->template->content->photo = $photo;
}
示例4: resizeImage
function resizeImage()
{
//lay duong dan file duoc request
$request = $_SERVER['REQUEST_URI'];
//lay ten file
$tmp_request = explode('/', $request);
$case = count($tmp_request);
$image_name = $tmp_request[$case - 1];
//type resize
$resize_type = $tmp_request[$case - 2];
//echo $image_name;
$resource_img = get_picture_dir($image_name) . '/' . $image_name;
$resource_img = '..' . $resource_img;
if (!file_exists($resource_img)) {
error_404_document();
}
//echo file_get_contents($resource_img);exit();
$images = new Image($resource_img);
$imageinfo = $images->getImageInfo();
if ($imageinfo['height'] == null || $imageinfo['height'] == 0) {
error_404_document();
}
//kich thuoc resize
$array_resize = array('large' => array(480, 360), 'medium' => array(240, 180), 'medium2' => array(145, 95), 'small' => array(106, 80), 'thumb' => array(50, 50), 'mobile' => array(640, 400), 'mobile_medium' => array(320, 200), 'mobile_small' => array(120, 75), 'mobile_low' => array(640, 400, 30), 'mobile_medium_low' => array(320, 200, 30), 'mobile_small_low' => array(120, 75, 30));
if (!isset($array_resize[$resize_type])) {
error_404_document();
}
//image name file no extension
$filesavename = explode('.', $image_name);
$count3 = count($filesavename);
if ($count3 > 1) {
unset($filesavename[$count3 - 1]);
}
$filesavename = implode('.', $filesavename);
$pathsave = '..' . get_picture_dir($image_name, $resize_type);
//nếu thư mục ảnh không tồn tại thì tạo mới
if (!file_exists($pathsave)) {
mkdir($pathsave, 0755, 1);
}
//echo $pathsave;die();
//kich thuoc resize ok -> tao file voi kich thuoc phu hop
$r_width = $array_resize[$resize_type][0];
$r_height = $array_resize[$resize_type][1];
if (isset($array_resize[$resize_type][2])) {
$r_quality = $array_resize[$resize_type][2];
} else {
$r_quality = 100;
}
if ($resize_type == 'organic') {
$images->resize($r_width, $r_height, 'fit', 'c', 'c', $r_quality);
} else {
$images->resize($r_width, $r_height, 'crop', 'c', 'c', $r_quality);
}
$images->save($filesavename, $pathsave);
header("HTTP/1.0 200 OK");
$images->display();
}
示例5: testSaveInBmp
/**
* Test
*
* @return void
*/
public function testSaveInBmp()
{
$savingPath = $this->directory . 'saving-test.bmp';
$this->object->open($this->directory . 'test.png');
$this->object->resize(50, 50);
$this->assertFalse($this->object->save($savingPath));
}
示例6: resize
public function resize($filename, $width, $height)
{
if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
return;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
try {
$image = new Image(DIR_IMAGE . $old_image);
} catch (Exception $exc) {
$this->log->write("The file {$old_image} has wrong format and can not be handled.");
$image = new Image(DIR_IMAGE . 'no_image.jpg');
}
$image->resize($width, $height);
$image->save(DIR_IMAGE . $new_image);
}
if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
return HTTPS_IMAGE . $new_image;
} else {
return HTTP_IMAGE . $new_image;
}
}
示例7: resize
public function resize($filename, $width, $height)
{
if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE) {
return;
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$image_old = $filename;
$image_new = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!is_file(DIR_IMAGE . $image_new) || filectime(DIR_IMAGE . $image_old) > filectime(DIR_IMAGE . $image_new)) {
list($width_orig, $height_orig, $image_type) = getimagesize(DIR_IMAGE . $image_old);
if (!in_array($image_type, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF))) {
return DIR_IMAGE . $image_old;
}
$path = '';
$directories = explode('/', dirname($image_new));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $image_old);
$image->resize($width, $height);
$image->save(DIR_IMAGE . $image_new);
} else {
copy(DIR_IMAGE . $image_old, DIR_IMAGE . $image_new);
}
}
if ($this->request->server['HTTPS']) {
return HTTPS_CATALOG . 'image/' . $image_new;
} else {
return HTTP_CATALOG . 'image/' . $image_new;
}
}
示例8: resize
function resize($path, $opt)
{
$f3 = \Base::instance();
$hash = $f3->hash($path . $f3->serialize($opt));
$new_file_name = $hash . '.jpg';
$dst_path = $f3->get('UPLOADS') . 'img/';
$path = explode('/', $path);
$file = array_pop($path);
if (!is_dir($dst_path)) {
mkdir($dst_path, 0775);
}
if (!file_exists($dst_path . $new_file_name)) {
$imgObj = new \Image($file, false, implode('/', $path) . '/');
$ow = $imgObj->width();
$oh = $imgObj->height();
if (!$opt['width']) {
$opt['width'] = round($opt['height'] / $oh * $ow);
}
if (!$opt['height']) {
$opt['height'] = round($opt['width'] / $ow * $oh);
}
$imgObj->resize((int) $opt['width'], (int) $opt['height'], $opt['crop'], $opt['enlarge']);
$file_data = $imgObj->dump('jpeg', null, $opt['quality']);
$f3->write($dst_path . $new_file_name, $file_data);
}
return $dst_path . $new_file_name;
}
示例9: resize
/**
*
* @param filename string
* @param width
* @param height
* @param type char [default, w, h]
* default = scale with white space,
* w = fill according to width,
* h = fill according to height
*
*/
public function resize($filename, $width, $height, $type = "")
{
if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
return;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type . '.' . $extension;
if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height, $type);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
}
}
if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
return (defined('HTTPS_STATIC_CDN') ? HTTPS_STATIC_CDN : $this->config->get('config_ssl')) . 'image/' . $new_image;
} else {
return (defined('HTTP_STATIC_CDN') ? HTTP_STATIC_CDN : $this->config->get('config_url')) . 'image/' . $new_image;
}
}
示例10: savePhoto
static function savePhoto($files, $thumbnail = [], $column = 'photo')
{
$root = f3()->get('ROOT') . f3()->get('BASE');
$path = "/upload/img/" . date("Y/m") . "/";
if ($files[$column]['size'] >= f3()->get('maxsize') || $files[$column]['size'] == 0) {
Reaction::_return("2002", "File too large. File must be less than 2 megabytes.");
}
if (!in_array($files[$column]['type'], f3()->get('photo_acceptable')) && !empty($files["photo"]["type"])) {
Reaction::_return("2003", 'Invalid file type. Only JPG, GIF and PNG types are accepted.');
}
if ($files[$column]['error'] != 0) {
Reaction::_return("2004", 'other error.');
}
if (!file_exists($root . $path)) {
mkdir($root . $path, 0777, true);
}
$path_parts = pathinfo($files[$column]['name']);
$old_fn = $path_parts['filename'];
$ext = $path_parts['extension'];
$filename = $path . substr(md5(uniqid(microtime(), 1)), 0, 15);
if (move_uploaded_file($files[$column]['tmp_name'], $root . $filename . "." . $ext)) {
list($width, $height, $type, $attr) = getimagesize($root . $filename . "." . $ext);
$img = new \Image($filename . "." . $ext, false, $root);
foreach ($thumbnail as $ns) {
$img->resize($ns[0], $ns[1], true);
file_put_contents($root . $filename . "_" . $ns[0] . "x" . $ns[1] . "." . $ext, $img->dump());
}
$new_fn = $filename . "." . $ext;
} else {
$new_fn = '';
$width = 0;
$height = 0;
}
return array($new_fn, $width, $height, $old_fn);
}
示例11: image
/**
* Image caching
*
* Resize & cache image into the file system. Returns the template image if product image is not exists
* At this time supports JPG images only
*
* @param mixed $name
* @param int $user_id
* @param int $width Resizing width
* @param int $height Resizing height
* @param bool $watermarked
* @param bool $overwrite
* @return string Cached Image URL
*/
public function image($name, $user_id, $width, $height, $watermarked = false, $overwrite = false)
{
$storage = DIR_STORAGE . $user_id . DIR_SEPARATOR . $name . '.' . ALLOWED_IMAGE_EXTENSION;
$cache = DIR_IMAGE . 'cache' . DIR_SEPARATOR . $user_id . DIR_SEPARATOR . $name . '-' . $width . '-' . $height . '.' . ALLOWED_IMAGE_EXTENSION;
$watermark = DIR_IMAGE . 'common' . DIR_SEPARATOR . 'watermark.png';
$cached_url = ($this->_request->getHttps() ? HTTPS_IMAGE_SERVER : HTTP_IMAGE_SERVER) . 'cache' . DIR_SEPARATOR . $user_id . DIR_SEPARATOR . $name . '-' . $width . '-' . $height . '.' . ALLOWED_IMAGE_EXTENSION;
// Force reset
if ($overwrite) {
unlink($cache);
}
// If image is cached
if (file_exists($cache)) {
return $cached_url;
// If image not cached
} else {
// Create directories by path if not exists
$directories = explode(DIR_SEPARATOR, $cache);
$path = '';
foreach ($directories as $directory) {
$path .= DIR_SEPARATOR . $directory;
if (!is_dir($path) && false === strpos($directory, '.')) {
mkdir($path, 0755);
}
}
// Prepare new image
$image = new Image($storage);
$image->resize($width, $height);
if ($watermarked) {
$image->watermark($watermark);
}
$image->save($cache);
}
return $cached_url;
}
示例12: resize
public function resize($filename, $width, $height)
{
if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE) {
return;
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$old_image = $filename;
$new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int) $width . 'x' . (int) $height . '.' . $extension;
if (!is_file(DIR_IMAGE . $new_image) || filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image)) {
$path = '';
$directories = explode('/', dirname($new_image));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
}
}
$new_image = str_replace(' ', '%20', $new_image);
if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1') || $this->request->server['HTTPS'] == '443') {
return $this->config->get('config_ssl') . 'image/' . $new_image;
} elseif (isset($this->request->server['HTTP_X_FORWARDED_PROTO']) && $this->request->server['HTTP_X_FORWARDED_PROTO'] == 'https') {
return $this->config->get('config_ssl') . 'image/' . $new_image;
} else {
return $this->config->get('config_url') . 'image/' . $new_image;
}
}
示例13: resize
public static function resize($filename, $width = 0, $height = 0)
{
if (!file_exists(Yii::app()->params['imagePath'] . $filename) || !is_file(Yii::app()->params['imagePath'] . $filename)) {
return;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
$new_image = substr($filename, 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
$cache_dir = Yii::app()->assetManager->getBasePath() . "/cache/";
if (!file_exists($cache_dir . $new_image) || filemtime(Yii::app()->params['imagePath'] . $old_image) > filemtime($cache_dir . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists($cache_dir . $path)) {
@mkdir($cache_dir . $path, 0777);
}
}
$image = new Image(Yii::app()->params['imagePath'] . $old_image);
$image->resize($width, $height);
$image->save($cache_dir . $new_image);
}
return Yii::app()->assetManager->getBaseUrl() . '/cache/' . $new_image;
}
示例14: uploadImage
/**
* Upload image
*/
public function uploadImage()
{
$upload_path = Filesystem::makeDir(UPLOADS . DS . 'images' . DS . 'pages' . DS . date('Y/m/d/'));
$filter = new Form_Filter_MachineName();
if (!empty($_POST['editor_file_link'])) {
$file = $upload_path . DS . $filter->value(basename($_POST['editor_file_link']));
$info = Image::getInfo($file);
copy($_POST['editor_file_link'], $file);
} else {
$image = new Upload_Image('file', array('path' => $upload_path));
if ($image->upload()) {
$info = $image->getInfo();
$file = $image->file->path;
//Ajax::json(array('succes'=>TRUE,'data'=>HTML::img(Url::toUri($image->file->path),$_POST['editor_file_alt'],array('width'=>$info->width,'height'=>$info->height))));
}
//Ajax::json(array('success'=>FALSE,'data'=>implode("\n",$image->errors)));
}
if (isset($file)) {
if ($max = config('pages.image.max', '600x600')) {
$size = explode('x', $max);
sizeof($size) == 1 && ($size[1] = $size[0]);
if ($info->width > $size[0] or $info->height > $size[1]) {
$image = new Image($file);
$image->resize($max);
$image->save();
}
}
exit(Url::toUri($file));
}
exit;
}
示例15: generate_thumb
public function generate_thumb()
{
$image = new Image($this->get_image_path());
$image->resize(200, 200);
$image->save($this->get_thumb_path());
return TRUE;
}