本文整理汇总了PHP中Image::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::save方法的具体用法?PHP Image::save怎么用?PHP Image::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::save方法的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: 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;
}
示例3: upload
public static function upload($tmp, $inmueble, $foto)
{
$root = "upload/{$inmueble}";
if (!is_dir($root)) {
mkdir($root, 0777);
chmod($root, 0777);
}
$imagen = new Image($tmp);
foreach (Inmuebles_Fotos::$sizes as $folder => $size) {
if (!is_dir("{$root}/{$folder}")) {
mkdir("{$root}/{$folder}", 0777);
chmod("{$root}/{$folder}", 0777);
}
if (true === $size) {
$imagen->clear();
$imagen->save("{$root}/{$folder}/{$foto}.jpg", Image::FORMAT_JPG);
continue;
}
$width = array_shift($size);
$height = array_shift($size);
$imagen->clear();
$imagen->resize($width, $height);
$imagen->save("{$root}/{$folder}/{$foto}.jpg", Image::FORMAT_JPG);
}
return true;
}
示例4: 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;
}
示例5: attachImage
protected function attachImage(Entity $entity, $url, $title = '', $caption = '', $is_featured = 1, $is_free = 0)
{
if (preg_match('/^https/', $url)) {
$this->printDebug("HTTPS protocol");
return false;
}
try {
$filename = ImageTable::createFiles($url, basename($url));
} catch (Exception $e) {
$this->printDebug($e);
return false;
}
if (!$filename) {
$this->printDebug("File could not be created");
return false;
}
$this->printDebug("Creating file: " . $filename);
//insert image row
$image = new Image();
$image->Entity = $entity;
$image->filename = $filename;
$image->url = $url;
$image->title = $title;
$image->caption = $caption;
$image->is_featured = $is_featured;
$image->is_free = $is_free;
$image->save();
$image->addReference($url, null, array('filename'));
$this->printDebug("Imported image with ID: " . $image->getId());
return true;
}
示例6: resize
function resize($filename, $width, $height)
{
$filename = trim($filename, '/');
if (!is_file(IMAGEPATH . $filename)) {
return;
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$old_image = $filename;
$new_image = 'cache/' . substr($filename, 0, strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
if (!is_file(IMAGEPATH . $new_image) || filectime(IMAGEPATH . $old_image) > filectime(IMAGEPATH . $new_image)) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(IMAGEPATH . $path)) {
@mkdir(IMAGEPATH . $path, 0777);
}
}
list($width_orig, $height_orig) = getimagesize(IMAGEPATH . $old_image);
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(IMAGEPATH . $old_image);
$image->resize($width, $height);
$image->save(IMAGEPATH . $new_image);
} else {
copy(IMAGEPATH . $old_image, IMAGEPATH . $new_image);
}
}
return IMAGEPATH . $new_image;
}
示例7: store
public function store()
{
$data = Input::all();
$album = new Album();
$album['title'] = $data['title'];
$album['user_id'] = Session::get('user')['id'];
$album['privacy'] = $data['privacy'];
$file = Input::file('img');
$folder_user = Session::get('user')['account'];
$album_path = 'public/upload/' . $folder_user . '/' . uniqid(date('ymdHisu'));
foreach ($file as $key => $f) {
$name = uniqid() . "." . $f->getClientOriginalExtension();
$f->move($album_path, $name);
if ($key == 0) {
// $album['album_img'] = $name;
$album->save();
FEEntriesHelper::save($album->id, FEEntriesHelper::getId("Album"), $album->user_id, $album->privacy);
}
$path = $album_path . '/' . $name;
$image = new Image();
$image['path'] = $path;
$image['user_id'] = Session::get('user')['id'];
$image['album_id'] = $album['id'];
$image['width'] = getimagesize($path)[0];
$image['height'] = getimagesize($path)[1];
$image->save();
}
echo json_encode($file);
}
示例8: save
public static function save($product_id, $index)
{
$data = Input::all();
$files = Input::file('img');
$status = true;
if ($files == null) {
Session::flash('status', 'false');
$messages[] = "Over max upload size!";
Session::flash('messages', $messages);
return false;
} else {
$image = new Image();
$file = $files[$index];
$upload_folder = "upload/products/" . uniqid(date('ymdHisu'));
$name = $file->getFilename() . uniqid() . "." . $file->getClientOriginalExtension();
$file->move(public_path() . "/" . $upload_folder, $name);
$image->path = '/public/' . $upload_folder . "/" . $name;
$image->product_id = $product_id;
$status = $image->save();
if ($status == FALSE) {
$status = true;
$messages[] = "Can't add product";
Session::flash('messages', $messages);
return false;
}
}
return true;
}
示例9: 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;
}
}
示例10: store
public function store()
{
$data = Input::all();
$data['is_single'] = 0;
$post = new Post();
$post->save();
$data['post_id'] = $post->id;
$album = AlbumsHelper::save($data);
$filesStatus = Input::get('file_status');
$upload_folder = "upload/albums/" . uniqid(date('ymdHisu'));
$files = Input::file('path');
$captions = Input::get('caption');
$status = 'success';
foreach ($files as $index => $file) {
if ($file->isValid() && $filesStatus[$index] != 0) {
$image = new Image();
$name = $file->getFilename() . uniqid() . "." . $file->getClientOriginalExtension();
$file->move(public_path() . "/" . $upload_folder, $name);
$post = new Post();
$post->save();
$image->path = $upload_folder . "/" . $name;
$image->caption = $captions[$index];
$image->album_id = $album->id;
$image->count_like = 0;
$image->post_id = $post->id;
$status = $image->save();
if ($status == FALSE) {
$status = 'fail';
break;
}
}
}
Session::flash('status', $status);
return Redirect::to('album/create');
}
示例11: 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));
}
示例12: 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;
}
示例13: afterSave
protected function afterSave()
{
parent::afterSave();
$images = CUploadedFile::getInstances($this, 'images');
if (isset($images) && count($images) > 0) {
foreach ($images as $k => $img) {
$imageName = md5(microtime()) . '.jpg';
if ($img->saveAs($this->getFolder() . $imageName)) {
$advImg = new Image();
$advImg->goods_id = $this->getPrimaryKey();
$advImg->image = $imageName;
$advImg->save();
}
}
}
if ($this->isNewRecord) {
$count = new Count();
$count->goods_id = $this->id;
$count->count = $this->count;
$count->size = $this->size;
$count->color = $this->color;
$count->save();
} else {
Count::model()->updateAll(array('goods_id' => $this->id, 'count' => $this->count, 'size' => $this->size, 'color' => $this->color), 'goods_id=:goods_id', array(':goods_id' => $this->id));
}
}
示例14: 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;
}
}
示例15: 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;
}