There's no way to get the byte size or other data about image transforms #19153
Unanswered
MoritzLost
asked this question in
Ideas
Replies: 1 comment
-
|
Just had another idea: Maybe we need a method to get an image transform as a binary blob, resource or file path. Of course, this method would always generate the transform immediately. Then we could use that to get the byte size and similar info. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I need to generate some image transforms and then return both the URL and byte size of the transformed image. However, there isn't any way to get information about the transform other than the URL. For example:
{% set image = craft.assets.kind('image').one() %} {% do craft.app.config.general.generateTransformsBeforePageLoad(true) %} {% do image.setTransform({ width: 1200 }) %} {# Correctly returns the URL of the transform. #} {% set url = image.getUrl() %} {# Returns the size of the _original_ image, not the transform. #} {% set size = image.size %}The transform has been generated and is on disk, but there is no way (except for a lot of hacking and reverse engineering through the asset transform index table) to get to either the file on disk or the byte size.
Arguably, if
setTransform()has been called,asset.sizeshould return the transformed image's size. But that would not be backwards compatible, would not work if image generation is deferred, and might cause problems with remote file systems.However, we need some way to get information about the transformed image beyond the URL. Right now, I only need the byte size, but I can imagine some other use cases.
Maybe a new method can be added that returns an array or data object with information about the transformed file?
Is there any non-hacky way to get the file size with what is available right now?
Beta Was this translation helpful? Give feedback.
All reactions