K
K
Ken Jee2016-10-11 09:36:12
Yii
Ken Jee, 2016-10-11 09:36:12

How to convert PNG to JPG in Yii2?

There is a task to accept only PNG and JPG files from the user. But PNG needs to be converted to JPG. How to implement this so that there are no problems if PNG has transparency?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2016-10-11
@Machez

I use this extension https://github.com/yurkinx/yii2-image
to solve problems with transparency, add background('#fff'), example:

$image->resize($width, $height, \yii\image\drivers\Image::ADAPT)->background('#fff');

D
Dmitry, 2016-10-11
@slo_nik

Good morning.
JPG does not support transparency.
If you need to accept only two types of files, why then convert png to jpg?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question