struct ImageSize
- ImageSize
- Struct
- Value
- Object
Defined in:
image_size.crConstructors
-
.get(bytes : Bytes) : ImageSize
Gets image size from binary data.
-
.get(filename : String) : ImageSize
Gets image size from filename.
Class Method Summary
-
.resize(bytes : Bytes, *, width = 0, height = 0) : Bytes
Resizes an image from binary data.
-
.resize(filename : String, *, width = 0, height = 0) : Bytes
Same as
self.resize
but reads the image from a filename.
Instance Method Summary
Constructor Detail
Gets image size from binary data.
file = File.new "test.png"
bytes = Bytes.new file.size
file.read bytes
file.close
size = ImageSize.get bytes
pp size.width
pp size.height
Gets image size from filename.
size = ImageSize.get "test.png"
pp size.width
pp size.height
Class Method Detail
Resizes an image from binary data.
NOTE At least one of the named arguments must be provided.
When only #width
is set, the #height
will be automatically calculated to
keep the aspect ratio.
bytes = ImageSize.resize data, width: 1024
File.write "1024.png", bytes
When only #height
is set, the #width
will be automatically calculated to
keep the aspect ratio.
bytes = ImageSize.resize data, height: 256
File.write "256.png", bytes
Seting both #width
and #height
will break the aspect ratio.
bytes = ImageSize.resize data, width: 1024, height: 1024
File.write "1024-1024.png", bytes
Same as self.resize
but reads the image from a filename.