CodeIgniter Forums
Compress image with ci 4 library removes png transparency and Incorrect APP1 Exif - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Compress image with ci 4 library removes png transparency and Incorrect APP1 Exif (/showthread.php?tid=78481)



Compress image with ci 4 library removes png transparency and Incorrect APP1 Exif - Kohryu - 01-27-2021

I am using compress image from codeigniter 4 library with below code :
Code:
\Config\Services::image()->withFile($this->request->getFile('storeimage'))->reorient()->save('images/store/test.png', 70)


But it removes transparency png image. Can i compress png image without losses the transparency in ci 4?

and also for some image i hit error below :
("exif_read_data(php3CBA.tmp):Incorrect APP1 Exif Identifier Code")


RE: Compress image with ci 4 library removes png transparency and Incorrect APP1 Exif - paulbalandan - 01-28-2021

If you are using v4.0.4 or below, there has already been a fix for this exif error in the develop branch. The next release will fix this.


RE: Compress image with ci 4 library removes png transparency and Incorrect APP1 Exif - Kohryu - 01-28-2021

(01-28-2021, 11:04 AM)paulbalandan Wrote: If you are using v4.0.4 or below, there has already been a fix for this exif error in the develop branch. The next release will fix this.

Noted with thanks.

How about the compress image?

I put below code in GDHanlder.php (save function) but it makes compress image not working, image size result still same and not compressed

Code:
imageAlphaBlending($this->resource, true);
imageSaveAlpha($this->resource, true);

Code:
case IMAGETYPE_PNG:
    imageAlphaBlending($this->resource, true);
    imageSaveAlpha($this->resource, true);

    if (! function_exists('imagepng'))
    {
        throw ImageException::forInvalidImageCreate(lang('images.pngNotSupported'));
    }

    if (! @imagepng($this->resource, $target))
    {
        throw ImageException::forSaveFailed();
    }
    break;



RE: Compress image with ci 4 library removes png transparency and Incorrect APP1 Exif - nahaK - 12-15-2024

You could try using a dedicated tool like png compressor alongside your CI 4 setup for compressing PNGs without losing transparency. It works well for maintaining quality and can complement your image handling process.