Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Issue using image library when original image and resized are the same size #3146

Closed
mihail-minkov opened this issue Jun 22, 2020 · 6 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@mihail-minkov
Copy link

Describe the bug
I am implementing an admin panel using CodeIgniter 4. I have a section where the user uploads slider images. I have the following code for the user upload:

$file = $this->request->getFile('slide_image');

if($file) {
    $original = $file->store();
    
    $dpre = 'uploads';
    if(!file_exists($dpre) and !is_dir($dpre)) {
        mkdir($dpre);
        chmod($dpre, 0755);
    }

    $dyear = $dpre.'/'.date("Y");
    if(!file_exists($dyear) and !is_dir($dyear)) {
        mkdir($dyear);
        chmod($dyear, 0755);
    }

    $dmonth = $dyear.'/'.date("m");
    if(!file_exists($dmonth) and !is_dir($dmonth)) {
        mkdir($dmonth);
        chmod($dmonth, 0755);
    }

    $d = $dmonth;

    $sizes = array(
        array(1919, 897),
        array(960, 449, true),
        array(480, 224, true),
    );

    $base_name = 'project_'.uniqid('abc_');

    foreach($sizes as $size) {
        $image = \Config\Services::image()
                    ->withFile('../writable/uploads/'.$original)
                    ->resize($size[0], $size[1], true)
                    ->reorient()
                    ->save($d.'/'.$size[0].'x'.$size[1].'_'.$base_name.'.'.$file->getExtension());
    }
}

If I use it like this and upload a 1920x897 image it works fine. But, if I change the 1919 to 1920 the scripts throws out an error that the folder is not writable.

CodeIgniter\Images\Exceptions\ImageException
Unable to save the image. Please make sure the image and file directory are writable.

This is literally the only difference. The original image I am uploading is 1920x897.

CodeIgniter 4 version
4.0.3

Affected module(s)
Image library

Context

  • OS: Windows 10 x64 Enterprise 1909
  • Web server: Apache/2.4.25 (Win64)
  • PHP version: 7.3.3
@mihail-minkov mihail-minkov added the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 22, 2020
@michalsn
Copy link
Member

Would you be able to check this using CI4-dev? I think it might be something related to the reorient() method which was updated in the development branch recently.

Another option would be to remove the reorient() method only to check if the problem persists.

@michalsn
Copy link
Member

I've just confirmed that this is fixed in the dev branch.

@mihail-minkov
Copy link
Author

So, just to understand, was it a reorient() issue or a problem related to dimensions?

@michalsn
Copy link
Member

Honestly, I haven't investigated it deeply. I just checked it on 4.0.3 to confirm the bug and then on 4-dev and it worked.

@mihail-minkov
Copy link
Author

So, the 4-dev when pushed would be 4.0.4? Just to be aware when to update.

@michalsn
Copy link
Member

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants