yii2-crop-image-upload icon indicating copy to clipboard operation
yii2-crop-image-upload copied to clipboard

Error if no image selected

Open makroxyz opened this issue 9 years ago • 5 comments

I must modify afterSave function in CropImageUploadBehavior

public function afterSave()
{
        parent::afterSave();

        if (in_array($this->owner->scenario, $this->scenarios)) {
            $image = null;

            foreach ($this->getConfigurations() as $crop) {
                if ($crop['_changed']) {
                    if (!$image) {
                        $path = $this->getUploadPath($this->attribute);
                        if (!$path) {
                            $path = $this->getUploadPath($this->attribute, true);
                        }
                    }
                    if ($path) {
                        $image = Image::getImagine()->open($path);
                        $this->createCrop($crop, $image->copy());
                    }
                }
            }
        }
    }

makroxyz avatar Apr 23 '15 12:04 makroxyz

could you send me error details? this change doesn't looks good for me

karpoff avatar Apr 23 '15 20:04 karpoff

Try to created a form with CropImageUpload field inside. Create a new record but don't upload any image... just leave it blank and save

This is the error message: Imagine\Exception\InvalidArgumentException File doesn't exist

makroxyz avatar Apr 24 '15 06:04 makroxyz

in this case $crop['_changed'] shouldn't be true will check

karpoff avatar Apr 24 '15 08:04 karpoff

@karpoff
Have you fixed this issue?

shahzadthathal avatar Oct 01 '15 07:10 shahzadthathal

I have changed CropImageUploadBehavior

protected function createCrop() { $path = $this->getUploadPath($this->attribute); if($path) $image = Image::getImagine()->open($path); else return true;

I know it is not correct way, but I'm waiting for solution :100:

shahzadthathal avatar Oct 01 '15 07:10 shahzadthathal