Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set file type #63

Open
pimago opened this issue May 12, 2022 · 5 comments
Open

Set file type #63

pimago opened this issue May 12, 2022 · 5 comments

Comments

@pimago
Copy link

pimago commented May 12, 2022

Maybe it is already possible and I don't find it. But it would be great to have a setting to change the file type after resizing an image. For example to webp.

@engram-design
Copy link
Member

Hmmm, I'd probably say it's out of scope for this plugin (we're just about resizing, not further manipulation), but anything is possible.

There's lots of complexities to converting images between JPG/PNG/GIF/SVG, and not to mention throwing in newer formats like WEBP/AVIF and even more older/obscure ones like TIFF/BMP. There's lots to consider that's possibly more in the realm of something like ImageOptimize

@pimago
Copy link
Author

pimago commented May 13, 2022

Thanks, I understand. I thought it would make sense because we can also set the quality and I was only thing about webp.

@acalvino4
Copy link

I agree this would be very useful.

It definitely would be expanding the scope of this plugin, but it would fit into the realm of "optimize assets on upload", which is the deeper purpose of this plugin.

Implementation-wise, I wonder if it may be as simple as hooking into the native transform system - basically define an image transform, and simply apply it on image upload.

@acalvino4
Copy link

Something like this as an outline?

$format = ImageResizer::$plugin->getSettings()->format;
if ($format) {
    $transform = new ImageTransform(['format' => $format]);
    $url = $asset->getUrl($transform);
    # somehow get asset path from $url above
    Craft::$app->assets->replaceAssetFile($asset, <asset-path>, $newfilename);
}

But I'm sure in reality that's probably only 10% of what you'd need to add...

@engram-design
Copy link
Member

I'll say that at the moment, "optimize assets on upload" is even out of scope for the plugin (which is why we'd pick ImageOptimize for that), but at some point, one day - we do want to include that functionality to Image Resizer.

It'd be great to have a free option to optimize images, and even change the filetype. All too often, out clients upload PNGs instead of JPEGs for images which can afford to be lossy. That wreaks a bit of havoc on image sizes.

We'll keep it all in mind!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants