Class: FreeImage::File
- Inherits:
-
AbstractSource
- Object
- AbstractSource
- FreeImage::File
- Defined in:
- lib/free-image/sources/file.rb
Overview
Instance Method Summary collapse
-
#format ⇒ Object
:call-seq: file.format -> :format.
-
#initialize(image_path) ⇒ File
constructor
Create a new FreeImage::File instance that can read and write image data from a file.
-
#save(bitmap, format, flags = 0) ⇒ Object
:call-seq: file.save(format = nil, flags = 0) -> boolean.
Methods inherited from AbstractSource
Constructor Details
#initialize(image_path) ⇒ File
Create a new FreeImage::File instance that can read and write image data from a file.
Parameters
- image_path
-
The full path to a image file.
58 59 60 |
# File 'lib/free-image/sources/file.rb', line 58 def initialize(image_path) @image_path = image_path end |
Instance Method Details
#format ⇒ Object
:call-seq:
file.format -> :format
Returns the image format for a file. If the image format cannot be determined then will return :unknown.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/free-image/sources/file.rb', line 68 def format result = FreeImage.FreeImage_GetFileType(@image_path, 0) FreeImage.check_last_error if result == :unknown # Try to guess the file format from the file extension result = FreeImage.FreeImage_GetFIFFromFilename(@image_path) FreeImage.check_last_error end result end |
#save(bitmap, format, flags = 0) ⇒ Object
:call-seq:
file.save(format = nil, flags = 0) -> boolean
Saves an image to a file.
Parameters
- format
-
The format to save the image to.
- flags
-
Format specific flags that control how a bitmap is saved. These flags are defined as constants on the AbstractSource class. Flags can be combined using Ruby’s bitwise or operator (|)
Usage
image = Bimap.open('<path_to_file>')
dst = File.new('<path_to_new_file>')
dst.save(image, :jpeg, AbtractSource::JPEG_QUALITYSUPERB | AbtractSource::JPEG_PROGRESSIVE)
98 99 100 101 102 |
# File 'lib/free-image/sources/file.rb', line 98 def save(bitmap, format, flags = 0) result = FreeImage.FreeImage_Save(format, bitmap, @image_path, flags) FreeImage.check_last_error result end |