Example #1
0
 private function saveImage($index, $album_id, $post)
 {
     $files = Input::file('path');
     $file = $files[$index];
     $name = $file->getFilename() . uniqid() . "." . $file->getClientOriginalExtension();
     $upload_folder = "upload/images/" . uniqid(date('ymdHisu'));
     $data['path'] = $upload_folder . "/" . $name;
     $data['album_id'] = $album_id;
     $captions = Input::get('caption');
     $data['caption'] = $captions[$index];
     $data['post_id'] = $post->id;
     App::make('FilesController')->save($file, $upload_folder, $name);
     return ImagesHelper::save($data);
 }
Example #2
0
    /**
     * Displays the contact page
     * @param int $id User's id
     */
    public function actionCreate() {

        $model = new Adverts;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if (isset($_POST['Adverts'])) {
            $model->attributes = $_POST['Adverts'];
            $model->user_id = Yii::app()->user->id;
            $model->created_at = date("Y-m-d H:i:s");
            $model->fields = serialize($_POST['Fields']);


            if ($model->save()) {
                $video = CUploadedFile::getInstances($model, 'youtube_id');
                //YoutubeHelper::processAdverts($model, $video);

                $images = CUploadedFile::getInstancesByName('images');
                // proceed if the images have been set
                ImagesHelper::processImages($model, $images);
                $this->redirect(array('adverts/view', 'id' => $model->id));
            }
        }

        $this->render('create', array(
            'model' => $model,
        ));
    }
 /**
  * Build overlay image from another image
  * @access public
  * @param  mixed    $image_source  - path to image source or gd image resource
  * @param  string   $watermark_img - path to watemark image source
  * @param  int      $alpha_level   - watemark image aplha level (default = 100)
  * @return resource gd resource
  */
 public static function overlay($image_source, $watermark_img, $position = 'random', $alpha_level = 50, $ratio = 0)
 {
     if (self::isgdloaded()) {
         $watermark_img = self::create($watermark_img);
         $width_src = self::width($image_source);
         $height_src = self::height($image_source);
         $image_source = self::create($image_source);
         $cnt = $ratio > 0 ? $ratio / 100 : 1;
         if ($width_src < self::width($watermark_img)) {
             $watermark_img = ImagesHelper::resizeto($watermark_img, round($width_src * $cnt), 'width');
         } elseif ($height_src < self::height($watermark_img)) {
             $watermark_img = ImagesHelper::resizeto($watermark_img, round($height_src * $cnt), 'height');
         }
         $watermark_width = self::width($watermark_img);
         $watermark_height = self::height($watermark_img);
         $coordinates = self::calculateposition($image_source, $watermark_img, $position);
         imagecopymerge($image_source, $watermark_img, $coordinates['dst_x'], $coordinates['dst_y'], 0, 0, $watermark_width, $watermark_height, $alpha_level);
         return $image_source;
     } else {
         return false;
     }
 }