Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master

* raise Vips::Error if `copy_memory` fails [VitaliiLazebnyi]

## Version 2.3.0 (2025-12-10)

* move library_name out of the global namespace and into FFI [jcupitt]
Expand Down
2 changes: 2 additions & 0 deletions lib/vips/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,8 @@ def add_alpha
# @return [Image] new memory image
def copy_memory
new_image = Vips.vips_image_copy_memory self
raise Vips::Error if new_image.null?

Vips::Image.new new_image
end

Expand Down
13 changes: 13 additions & 0 deletions spec/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@
expect { img.write_to_memory }.to raise_exception(Vips::Error)
end

it "can copy an image to memory" do
image = (Vips::Image.black(16, 16) + 128).copy_memory

expect(image.width).to eq(16)
expect(image.height).to eq(16)
expect(image.avg).to eq(128)
end

it "will raise VipsError if copy_memory fails" do
img = Vips::Image.new_from_file simg("coffee.gif")
expect { img.copy_memory }.to raise_exception(Vips::Error)
end

it "throws an error when trying to load an image from memory with unknown size" do
data = FFI::Pointer.new(1)
expect { Vips::Image.new_from_memory(data, 16, 16, 1, :uchar) }.to raise_error(Vips::Error)
Expand Down
Loading