OleksandrWebLab / oc-image-compress-plugin

Simple compression and resize for images
MIT License
6 stars 2 forks source link

Error compressing images after upload #4

Closed chocolata closed 6 years ago

chocolata commented 6 years ago

Hi,

I've installed your plugin on my development environment (Xampp) and on my staging environment (CentOS Linux 7.4.1708).

When I upload an image:

        $mannequin= new Mannequin();
        $mannequin->name = Input::get('name');
        ...
        $mannequin->save();

        // ATTACHTHE IMAGES
        if(Input::file('image_1')) {
            $mannequin->images()->create(['data' => Input::file('image_1')]);
        }
        if(Input::file('image_2')) {
            $mannequin->images()->create(['data' => Input::file('image_2')]);
        }
        if(Input::file('image_3')) {
            $mannequin->images()->create(['data' => Input::file('image_3')]);
        }
        if(Input::file('image_4')) {
            $mannequin->images()->create(['data' => Input::file('image_4')]);
        }
        if(Input::file('image_5')) {
            $mannequin->images()->create(['data' => Input::file('image_5')]);
        }
        if(Input::file('image_6')) {
            $mannequin->images()->create(['data' => Input::file('image_6')]);
        }

image_1 to image_6 are compressed and added to my model as they should, at least on my development environment.

On my staging server however, I get the error message stating:

ErrorException: imagesx() expects parameter 1 to be resource, boolean given in /var/www/vhosts/domain.com/subdomains/testcase/vendor/october/rain/src/Database/Attach/Resizer.php:210

When I disable the compression plugin, everything seems to be working fine. What do you think might be the problem?

P.S.: Loving your plugin by the way. Many thanks for developing it. It was just what I needed. I'm sure we can get it working.

OrlovEvgeny commented 6 years ago

use new file watcher runtime compressing https://github.com/OrlovEvgeny/TinyJPG

chocolata commented 6 years ago

Hi, thank you for your answer, but I don't understand what you mean. Can you explain?

OrlovEvgeny commented 6 years ago

Compress images while running php code, this is not the best option, this approach will create a high load. Use tinyjpg. It works as a background process and compresses images as soon as they appear in the directory.

chocolata commented 6 years ago

Thanks, but I'd really rather try to only compress images as intented by this plugin. Might you have any clue what could be wrong?

chocolata commented 6 years ago

Does anyone have an idea?

OleksandrWebLab commented 6 years ago

The reason can be either.

You have a library installed GD? Function imagecreatefromjpeg() can not open the file, so it returns false. The function is described in a file vendor/october/rain/src/Database/Attach/Resizer.php:474

Try temporarily removing @ before the function (on this file, on this line), to understand why the function returns false. Check logs and check which permissions are set on the directory that this function accesses.

I do not see this as my fault, because I use only system functions. Also I think a function {{ image.thumb(255, 255, 'crop') }} should not work

chocolata commented 6 years ago

Thank you so much for your answer. I've managed to find out now that one of the JPEG files was corrupted.

ErrorException: imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 92 extraneous bytes before marker 0xd9
in /var/www/vhosts/domains.com/httpdocs/vendor/october/rain/src/Database/Attach/Resizer.php:474

That solves it, thank you very much. I did see, however, an issue where smaller images than my set size are enlarged. I'll open up a new issue and close this one.