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