Closed GSAir closed 10 years ago
It seems to work.
It may me think that the quality should be restore after the save function in order to avoid some problems no?
I just commited a patch.
I think it's fine to have the quality be a side effect (?).
More concerning is the format issue: if you load a png, then the internal format is set to png, so any subsequent call you'll do to toBlob() will use the png encoder. Worse: if you create an gm.Image(tensor) from a tensor, which I often do, then toBlob() returns an empty blob, because no format is set I guess. Any idea on these?
Scratch that, I provide a function format(), which you can use to do exactly that... I forgot about that:
local i = gm.Image('image.png')
i:format('JPG')
local res = i:toString(90)
-- res will contain a jpeg, encoded with a quality of 90%
require 'image'
local img = image.lena()
local i = gm.Image(img, 'RGB', 'DHW')
-- image has no format at that point
i:format('JPG')
local res = i:toString(90)
-- res will contain a jpeg, encoded with a quality of 90%
Seems perfect, thanks. I was thinking that the wand was global, but in fact it is for each image, the side effect shouldn't be a problem.
Res will be an ascii format then? And i:toBlob() will be the byte representation?
Is there an easy way to compress before sending
toBlob
?I see how to do it with save, but I would have to
load
,save
andreload
.Can we add:
in the function toBlob? I am not sure if it will do the trick though.