[5.7] Image to JPG when generating a thumbnail?

Many of the images on my website are uploaded in PNG format.
When I am generating a thumbnail from them, I'd like to convert them to JPG.

I do have something like this:
use \Imagine\Image\ImageInterface;
use \Concrete\Core\File\Image\Thumbnail\Thumbnail as Thumbnail;
use \Concrete\Core\File\Image\Thumbnail\Type\Type;
$type = new Type();
$type = $type->getByHandle('average_image');
   $type = new Type();
$f = File::getByID(1);

However, this outputs a PNG file with a .jpg extension - with transparency and everything.

View Replies: View Best Answer
PineCreativeLabs replied on at Permalink Reply
Somewhere in your output, you could use str_replace to drop the PNG extenstion. For example:

$image = 'path_thumbnail';
$search = 'png';
$trimmed = str_replace($search, "", $image);
echo $trimmed;

Or something like that.
MoonGrab replied on at Permalink Best Answer Reply
Yeah, not sure if that solves anything. I've opened a GitHub issue (https://github.com/concrete5/concrete5/issues/2556), let's see what the core team thinks about this.

Meanwhile, what we did was copy the old image helper with some light modifications. Here's what we did:
1) Create folder: /application/src/
2) Create file: /application/src/JpegImageHelper.php with the following content:
namespace Application\Src;
use Config;
use Loader;
use Image;
use \Imagine\Image\Box;
use Imagine\Image\ImageInterface;
use \Imagine\Image\Point\Center;
use \Concrete\Core\File\File;
class JpegImageHelper
    function replace_extension($filename, $new_extension) {
        $info = pathinfo($filename);
        return $info['filename'] . '.' . $new_extension;

4) Use it like this:
use Application\Src\JpegImageHelper as ImageCompressor;
$ih = new ImageCompressor();

From there, you can use it as you'd normally use the image helper. It's not the prettiest solution but it works.