bupy7 / yii2-widget-cropbox

This widget allows crop image before upload to server and send informations about crop in JSON format.
BSD 3-Clause "New" or "Revised" License
91 stars 33 forks source link

How to save the cropped picture for beginner? #35

Closed Starite closed 7 years ago

Starite commented 7 years ago

Here's my controller

public function actionCreate()
    {
        $model = new Carousel();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {           
             $model->images = UploadedFile::getInstance($model, 'images');  
            $model->path = '../web/images/banners/'. $model->images->baseName . '_' . time() . '.' . $model->images->extension;         
            $model->save();          
            $model->images->saveAs('images/banners/' . $model->images->baseName . '_' . time() . '.' . $model->images->extension); 
            return $this->redirect(['carousel/index']);
        } else {
            return $this->render('create', [
                'model' => $model,
            ]);
        }
    }`

My model

 public $images;
    public $crop_info;
    public static function tableName()
    {
        return 'carousel';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'integer'],
            [['path', 'heading', 'content', 'link'], 'string'],
            [['images'], 'file', 'extensions' => 'png, jpg, gif, jpeg', 'maxSize'=>1024*1024*10],
            ['crop_info', 'safe'],
        ];
    }`
`

My View

<?= $form->field($model, 'images')->widget(Cropbox::className(), [ 'attributeCropInfo' => 'crop_info', ]);?>

With this I can only save the original picture not the cropped picture. I could not figure out how to save the cropped picture. Please help me with this.

Thank you!

bupy7 commented 7 years ago

Read manual, please. https://github.com/bupy7/yii2-widget-cropbox#how-use

Starite commented 7 years ago

I've read it but I don't understand most of it. I don't use Imagine extension and I use controller to save image. Can you tell me how can I save the cropped image using controller? Thank you!

bupy7 commented 7 years ago

The cropped picture you can save only use Imagine extension or a similar it.

Starite commented 7 years ago

Thank you :)