Welcome Guest, Not a member yet? Register   Sign In
Fix Codeigniter 4.1.9 Error
#1

(This post was last modified: 04-29-2022, 09:56 PM by pvt.)

Hi all!
I am using Codeigniter 4.1.9 with php version 8.1 when i used image class to make Text WaterMark, Convert Image;  It have some error with GD Library. I was fixed them. Now, I share my solution:
1. Text WaterMark:
- User guide code:
Code:
\Config\Services::image('imagick')
    ->withFile('/path/to/image/mypic.jpg')
    ->text('Copyright 2017 My Photo Co', [
        'color'      => '#fff',
        'opacity'    => 0.5,
        'withShadow' => true,
        'hAlign'    => 'center',
        'vAlign'    => 'bottom',
        'fontSize'  => 20
    ])
    ->save('/path/to/new/image.jpg');

- Error message:
Code:
"Implicit conversion from float 88.89999999999999 to int loses precision" (error convert float to INT).

- Reason: In PHP.NET, function imagecolorclosestalpha() - with opacity parameter must be int value. Follow user guide document, opacity pass to here will be float value
- Solution: convert opacity to int value (0-127) by ceil() function - parameter.  
File: system\Images\Handlers\GDHandler.php
Line: 464
Add code: 
PHP Code:
$opacity ceil($opacity);  


 Another function, with xAsis - yAsis i was used ceil() function to convert float to int value.

2. Convert Imageg\Ser

User guide code:
Code:
\Config\Services::image()
    ->withFile('/path/to/image/mypic.jpg')
    ->convert(IMAGETYPE_PNG)
    ->save('/path/to/new/image.png');

Note: When I read sample code, I thought parameter for convert function is destination file but it wrong; parameter for convert() function must equal source file extension - with file save you can set new file (ex: *.png) 
You can get source file extension  with function pathinfo(). I hope this topic can help any body. Thanks for reading!
-
3.A
Reply
#2

Thank you!
I created an issue.
https://github.com/codeigniter4/CodeIgni...ssues/5941
Reply
#3

(This post was last modified: 05-06-2022, 05:25 AM by kenjis.)

(04-29-2022, 09:55 PM)pvt Wrote: 2. Convert Imageg\Ser

User guide code:
Code:
\Config\Services::image()
    ->withFile('/path/to/image/mypic.jpg')
    ->convert(IMAGETYPE_PNG)
    ->save('/path/to/new/image.png');

Note: When I read sample code, I thought parameter for convert function is destination file but it wrong; parameter for convert() function must equal source file extension - with file save you can set new file (ex: *.png) 
You can get source file extension  with function pathinfo(). I hope this topic can help any body. Thanks for reading!
-
3.A

The documentation is no wrong. There is a bug.
See https://github.com/codeigniter4/CodeIgni...ssues/5966
The bug was fixed in the develop branch, and will be included in v4.2.0.

(04-29-2022, 09:55 PM)pvt Wrote:
Code:
\Config\Services::image('imagick')
    ->withFile('/path/to/image/mypic.jpg')
    ->text('Copyright 2017 My Photo Co', [
        'color'      => '#fff',
        'opacity'    => 0.5,
        'withShadow' => true,
        'hAlign'    => 'center',
        'vAlign'    => 'bottom',
        'fontSize'  => 20
    ])
    ->save('/path/to/new/image.jpg');

- Error message:
Code:
"Implicit conversion from float 88.89999999999999 to int loses precision" (error convert float to INT).

This bug was also fixed.
https://github.com/codeigniter4/CodeIgni...ssues/5941
Reply
#4

(04-29-2022, 09:55 PM)pvt Wrote: Hi all!
I am using Codeigniter 4.1.9 with php version 8.1 when i used image class to make Text WaterMark, Convert Image;  It have some error with GD Library. I was fixed them. Now, I share my solution:
1. Text WaterMark:
- User guide code:
Code:
\Config\Services::image('imagick')
    ->withFile('/path/to/image/mypic.jpg')
    ->text('Copyright 2017 My Photo Co', [
        'color'      => '#fff',
        'opacity'    => 0.5,
        'withShadow' => true,
        'hAlign'    => 'center',
        'vAlign'    => 'bottom',
        'fontSize'  => 20
    ])
    ->save('/path/to/new/image.jpg');

- Error message:
Code:
"Implicit conversion from float 88.89999999999999 to int loses precision" (error convert float to INT).

- Reason: In PHP.NET, function imagecolorclosestalpha() - with opacity parameter must be int value. Follow user guide document, opacity pass to here will be float value
- Solution: convert opacity to int value (0-127) by ceil() function - parameter.  
File: system\Images\Handlers\GDHandler.php
Line: 464
Add code: 
PHP Code:
$opacity ceil($opacity);  


 Another function, with xAsis - yAsis i was used ceil() function to convert float to int value.

2. Convert Imageg\Ser

User guide code:
Code:
\Config\Services::image()
    ->withFile('/path/to/image/mypic.jpg')
    ->convert(IMAGETYPE_PNG)
    ->save('/path/to/new/image.png');

Note: When I read sample code, I thought parameter for convert function is destination file but it wrong; parameter for convert() function must equal source file extension - with file save you can set new file (ex: *.png) 
You can get source file extension  with function pathinfo(). I hope this topic can Myaccountaccess help any body. Thanks for reading!
-
3.A

I have also faced same issue. Did you really find solution??
Reply
#5

(12-22-2022, 12:46 AM)simonagjerner Wrote: I have also faced same issue. Did you really find solution??

Have you read the whole thread?
Quote:The bug was fixed in the develop branch, and will be included in v4.2.0.
Reply
#6

Hi all!
When attempting to use the image class in Codeigniter 4.1.9 with PHP 8.1 to create a Text WaterMark or convert an image, I encountered an error related to the GD Library. I was able to fix them.

Note: I misunderstood the sample code and thought the flyingtogether
parameter for the convert function was the file to which the converted data would be written. Instead, the parameter for the convert() function must equal the extension of the file from which the data will be converted.
The function pathinfo can be used to determine the extension of a source file.(). Please let this topic be of some use to someone. Much appreciation for taking the time to read this!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB