save() public method

public save ( $file, $quality = 90 )
Esempio n. 1
11
 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;
     }
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
 /**
  * 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;
 }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
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;
}
Esempio n. 7
0
 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);
 }
Esempio n. 8
0
 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;
 }
Esempio n. 9
0
 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;
     }
 }
Esempio n. 10
0
 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');
 }
Esempio n. 11
0
 /**
  * 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));
 }
Esempio n. 12
0
 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;
 }
Esempio n. 13
0
 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));
     }
 }
Esempio n. 14
0
 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;
     }
 }
Esempio n. 15
0
 /**
  * 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;
 }
Esempio n. 16
0
 static function process_image($arr, $user)
 {
     //save the uploaded image to database, return new Image id or error code on success/failure
     //$arr is the same as $_FILES['upload']
     if (@(!isset($arr))) {
         return 0;
     }
     if ($arr['error'] > 0) {
         return -1;
     }
     $allowed_types = array('image/jpeg', 'image/jpg', 'image/gif', 'image/png');
     if (!in_array($arr['type'], $allowed_types)) {
         return -2;
     }
     if ($arr['size'] > 100000) {
         return -3;
     }
     $file_info = getimagesize($arr['tmp_name']);
     if (empty($file_info)) {
         return -4;
     }
     $new_filename = time() . "_" . $arr['name'];
     if (!move_uploaded_file($arr['tmp_name'], "images/{$new_filename}")) {
         return -5;
     }
     if (file_exists($arr['tmp_name']) && is_file($arr['tmp_name'])) {
         unlink($arr['tmp_name']);
     }
     $image = new Image(array("path" => $new_filename, "owner" => $user->get_id()));
     $result = $image->save();
     if (!$result) {
         return -6;
     }
     return $result;
 }
Esempio n. 17
0
 /**
  *	
  *	@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);
         }
     }
     return $this->getImageUrl($new_image);
 }
Esempio n. 18
0
 protected function afterSave()
 {
     parent::afterSave();
     require_once 'Image.php';
     // 保存图片
     if ($this->bannerFile instanceof CUploadedFile && $this->hasErrors('bannerFile') == false) {
         // 保存原文件
         $file = $this->bannerFile;
         $fileName = md5($file->tempName . uniqid()) . '.' . $file->extensionName;
         //list($width, $height, $type, $attr) = getimagesize($file->tempName);
         $filePath = Helper::mediaPath(self::UPLOAD_LARGE_IMAGE_PATH . $fileName, FRONTEND);
         $file->saveAs($filePath);
         if (strtolower($file->extensionName) != 'swf') {
             $image = new Image($filePath);
             $image->save(Helper::mediaPath(self::UPLOAD_LARGE_IMAGE_PATH . $fileName, FRONTEND));
         }
         // 更新数据
         $this->updateByPk($this->primaryKey, array('banner_path' => $fileName));
     } else {
         if ($this->deleteBannerFile) {
             // 删除图片
             @unlink(Helper::mediaPath(self::UPLOAD_LARGE_IMAGE_PATH . $this->banner_path, FRONTEND));
             // 更新数据
             $this->updateByPk($this->primaryKey, array('banner_path' => ''));
         }
     }
 }
Esempio n. 19
0
 /**
  * @param $id
  * @throws CDbException
  * @throws CHttpException
  */
 public function actionView($id)
 {
     if (($gallery = Gallery::model()->published()->findByPk($id)) === null) {
         throw new CHttpException(404, Yii::t('GalleryModule.gallery', 'Page was not found!'));
     }
     $image = new Image();
     if (Yii::app()->getRequest()->getIsPostRequest() && !empty($_POST['Image'])) {
         try {
             $transaction = Yii::app()->db->beginTransaction();
             $image->attributes = $_POST['Image'];
             if ($image->save() && $gallery->addImage($image)) {
                 $transaction->commit();
                 Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('GalleryModule.gallery', 'Photo was created!'));
                 $this->redirect(['/gallery/gallery/view', 'id' => $gallery->id]);
             }
         } catch (Exception $e) {
             $transaction->rollback();
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, $e->getMessage());
         }
     }
     if ($gallery->status == Gallery::STATUS_PRIVATE && $gallery->owner != Yii::app()->user->id) {
         throw new CHttpException(404);
     }
     $this->render('view', ['image' => $image, 'model' => $gallery]);
 }
Esempio n. 20
0
 public function resize($filename, $width, $height)
 {
     if (!is_file(DIR_IMAGE . $filename)) {
         return;
     }
     $extension = pathinfo($filename, PATHINFO_EXTENSION);
     $old_image = $filename;
     $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension;
     if (!is_file(DIR_IMAGE . $new_image) || filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image)) {
         $path = '';
         $directories = explode('/', dirname(str_replace('../', '', $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);
         }
     }
     if ($this->request->server['HTTPS']) {
         return $this->config->get('config_ssl') . 'image/' . $new_image;
     } else {
         return $this->config->get('config_url') . 'image/' . $new_image;
     }
 }
Esempio n. 21
0
 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;
     }
 }
Esempio n. 22
0
 public function generate_thumb()
 {
     $image = new Image($this->get_image_path());
     $image->resize(200, 200);
     $image->save($this->get_thumb_path());
     return TRUE;
 }
Esempio n. 23
0
 public function readFolder()
 {
     $folder = $this->customer->getFolderName();
     $dir = DIR_IMAGE . "catalog/" . $folder;
     $allfiles = scandir($dir);
     $img_links = array();
     $counting = 0;
     foreach ($allfiles as $image) {
         //if the file is not hidden get the the URI
         if (substr($image, 0, 1) != '.') {
             //Once we get certified the config.php needs to be modified.
             $modify_image = new Image(DIR_IMAGE . "catalog/" . $folder . "/" . $image);
             // $mark = new Image(DIR_IMAGE. "logo.png");
             $width = $modify_image->getWidth() * 0.2;
             $height = $modify_image->getHeight() * 0.2;
             // $mark->resize($width, $height);
             // $modify_image->watermark($mark);
             $size = $width * $height;
             $modify_image->save($modify_image->getFile());
             $img_links[$counting]['source'] = HTTPS_SERVER . "/image/catalog/" . $folder . "/" . $image;
             $img_links[$counting]['width'] = $modify_image->getWidth();
             $img_links[$counting]['height'] = $modify_image->getHeight();
             $counting++;
         }
     }
     return $img_links;
 }
Esempio n. 24
0
 public function upload()
 {
     $file = Input::file('file');
     $input = array('image' => $file);
     $rules = array('image' => 'image');
     $validator = Validator::make($input, $rules);
     $imagePath = 'public/uploads/';
     $thumbPath = 'public/uploads/thumbs/';
     $origFilename = $file->getClientOriginalName();
     $extension = $file->getClientOriginalExtension();
     $mimetype = $file->getMimeType();
     if (!in_array($extension, $this->whitelist)) {
         return Response::json('Supported extensions: jpg, jpeg, gif, png', 400);
     }
     if (!in_array($mimetype, $this->mimeWhitelist) || $validator->fails()) {
         return Response::json('Error: this is not an image', 400);
     }
     $filename = str_random(12) . '.' . $extension;
     $image = ImageKit::make($file);
     //save the original sized image for displaying when clicked on
     $image->save($imagePath . $filename);
     // make the thumbnail for displaying on the page
     $image->fit(640, 480)->save($thumbPath . 'thumb-' . $filename);
     if ($image) {
         $dbimage = new Image();
         $dbimage->thumbnail = 'uploads/thumbs/thumb-' . $filename;
         $dbimage->image = 'uploads/' . $filename;
         $dbimage->original_filename = $origFilename;
         $dbimage->save();
         return $dbimage;
     } else {
         return Response::json('error', 400);
     }
 }
Esempio n. 25
0
 public function post_instagram()
 {
     // fetch input data
     $input = Input::all();
     // create rules for validator
     $rules = array('image' => 'required|unique:images', 'description' => 'required|max:100');
     // validate the data with set rules
     $v = Validator::make($input, $rules);
     if ($v->fails()) {
         // if validation fails, redirect back with relevant error messages
         return Redirect::back()->withErrors($v);
     } else {
         // store image info in the database
         $image = Input::all('image');
         $img = new Image();
         $img->description = Input::get('description');
         $img->image = $image['image'];
         $img->user_id = Auth::user()->id;
         $img->approved = "0";
         $saveflag = $img->save();
         if ($saveflag) {
             return Redirect::back()->withErrors('Upload Successful!');
         }
     }
 }
Esempio n. 26
0
 protected function afterSave()
 {
     parent::afterSave();
     $this->validateBannerFile('bannerFile', null);
     require_once 'Image.php';
     // 保存图片
     if ($this->hasErrors('bannerFile') == false && $this->bannerFile instanceof CUploadedFile) {
         // 保存原图
         $file = $this->bannerFile;
         $fileName = md5($file->tempName . uniqid()) . '.' . $file->extensionName;
         $filePath = Helper::mediaPath(Banner::UPLOAD_LARGE_IMAGE_PATH . $fileName, FRONTEND);
         $file->saveAs($filePath);
         // 如果是图片需要进行裁切
         // 右侧底图
         if (strtolower($file->extensionName) != 'swf') {
             $image = new Image($filePath);
             $image->save(Helper::mediaPath(Banner::UPLOAD_LARGE_IMAGE_PATH . $fileName, FRONTEND));
         }
         // 更新数据
         $this->updateByPk($this->primaryKey, array('banner_path' => $fileName));
     } else {
         if ($this->deleteBannerFile) {
             @unlink(Helper::mediaPath(Banner::UPLOAD_LARGE_IMAGE_PATH . $this->banner_path, FRONTEND));
             // 更新数据
             $this->updateByPk($this->primaryKey, array('banner_path' => ''));
         }
     }
 }
 /**
  *	
  *	@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;
     }
 }
Esempio n. 28
0
 public static function genImgForSlider($apartmentId)
 {
     $mainImage = Images::getMainImageData(null, $apartmentId);
     if ($mainImage) {
         $imgName = $mainImage['file_name'];
         Yii::import('application.extensions.image.Image');
         $pathImg = DIRECTORY_SEPARATOR . Images::UPLOAD_DIR . DIRECTORY_SEPARATOR . Images::OBJECTS_DIR . DIRECTORY_SEPARATOR . $apartmentId . DIRECTORY_SEPARATOR . Images::ORIGINAL_IMG_DIR . DIRECTORY_SEPARATOR . $imgName;
         $sliderDir = DIRECTORY_SEPARATOR . Images::UPLOAD_DIR . DIRECTORY_SEPARATOR . Images::OBJECTS_DIR . DIRECTORY_SEPARATOR . $apartmentId . DIRECTORY_SEPARATOR . Images::MODIFIED_IMG_DIR . DIRECTORY_SEPARATOR;
         if ($mainImage['file_name_modified']) {
             $name = $mainImage['file_name_modified'];
         } else {
             $name = Images::updateModifiedName($mainImage);
         }
         $sliderImgName = 'thumb_' . param('slider_img_width', 500) . 'x' . param('slider_img_height', 280) . '_' . $name;
         $pathImgSlider = $sliderDir . DIRECTORY_SEPARATOR . $sliderImgName;
         if (!is_dir(ROOT_PATH . $sliderDir)) {
             @mkdir(ROOT_PATH . $sliderDir);
         }
         @unlink(ROOT_PATH . $pathImgSlider);
         if (!file_exists(ROOT_PATH . $pathImgSlider)) {
             $image = new Image(ROOT_PATH . $pathImg);
             $image->resizeWithEffect(param('slider_img_width', 500), param('slider_img_height', 280));
             $image->save(ROOT_PATH . $pathImgSlider);
             return true;
         } else {
             return true;
         }
     }
     return false;
 }
Esempio n. 29
0
 /**
  * Saves image to defined location with defined quality
  *
  * @param $location
  * @param int $quality
  * @return Kohana_Imagify
  * @throws Imagify_Exception
  */
 public function save($location, $quality = 80)
 {
     if (!isset($this->_image)) {
         throw new Imagify_Exception('Image is not yet created to save');
     }
     $this->_image->save($location, $quality);
     return $this;
 }
Esempio n. 30
0
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();
}