image_science-1.2.2/0000755000004100000410000000000011734360156014325 5ustar www-datawww-dataimage_science-1.2.2/test/0000755000004100000410000000000011734360156015304 5ustar www-datawww-dataimage_science-1.2.2/test/pix.png0000444000004100000410000000220411734360156016606 0ustar www-datawww-dataPNG  IHDR22] pHYs  6IDATXKoEU=c>X"% D*$P@H `q &+?wgCֶ^*HvgzSUSU=MD"+z zz,"惏<P=GX>k` 8` 8zz0 bx auS"@@Ŷ/ fSMn(k֫[?./G|iOs B`'[jhJ1 >XiοJ\ s"vw[}erf_|7?۸s_<ؓG[?Iޮ0@l֚ۛ֒;mލp" 43 B:*̖\A%.̕HERef{@Ȝ#[`he‚sj5uN@Wkt&ظZ|nlp)9t[@z2B"֫>~҂9p~f jr9f3Zx-"&mSIzpCM> UO true end require 'rubygems' require 'minitest/unit' require 'minitest/autorun' if $0 == __FILE__ require 'image_science' class TestImageScience < MiniTest::Unit::TestCase def setup @path = 'test/pix.png' @tmppath = 'test/pix-tmp.png' @h = @w = 50 end def teardown File.unlink @tmppath if File.exist? @tmppath end def test_class_with_image ImageScience.with_image @path do |img| assert_kind_of ImageScience, img assert_equal @h, img.height assert_equal @w, img.width assert img.save(@tmppath) end assert File.exists?(@tmppath) ImageScience.with_image @tmppath do |img| assert_kind_of ImageScience, img assert_equal @h, img.height assert_equal @w, img.width end end def test_class_with_image_missing assert_raises TypeError do ImageScience.with_image @path + "nope" do |img| flunk end end end def test_class_with_image_missing_with_img_extension assert_raises RuntimeError do assert_nil ImageScience.with_image("nope#{@path}") do |img| flunk end end end def test_class_with_image_from_memory data = File.new(@path).binmode.read ImageScience.with_image_from_memory data do |img| assert_kind_of ImageScience, img assert_equal @h, img.height assert_equal @w, img.width assert img.save(@tmppath) end assert File.exists?(@tmppath) ImageScience.with_image @tmppath do |img| assert_kind_of ImageScience, img assert_equal @h, img.height assert_equal @w, img.width end end def test_class_with_image_from_memory_empty_string assert_raises TypeError do ImageScience.with_image_from_memory "" do |img| flunk end end end def test_resize ImageScience.with_image @path do |img| img.resize(25, 25) do |thumb| assert thumb.save(@tmppath) end end assert File.exists?(@tmppath) ImageScience.with_image @tmppath do |img| assert_kind_of ImageScience, img assert_equal 25, img.height assert_equal 25, img.width end end def test_resize_floats ImageScience.with_image @path do |img| img.resize(25.2, 25.7) do |thumb| assert thumb.save(@tmppath) end end assert File.exists?(@tmppath) ImageScience.with_image @tmppath do |img| assert_kind_of ImageScience, img assert_equal 25, img.height assert_equal 25, img.width end end def test_resize_zero assert_raises ArgumentError do ImageScience.with_image @path do |img| img.resize(0, 25) do |thumb| assert thumb.save(@tmppath) end end end refute File.exists?(@tmppath) assert_raises ArgumentError do ImageScience.with_image @path do |img| img.resize(25, 0) do |thumb| assert thumb.save(@tmppath) end end end refute File.exists?(@tmppath) end def test_resize_negative assert_raises ArgumentError do ImageScience.with_image @path do |img| img.resize(-25, 25) do |thumb| assert thumb.save(@tmppath) end end end refute File.exists?(@tmppath) assert_raises ArgumentError do ImageScience.with_image @path do |img| img.resize(25, -25) do |thumb| assert thumb.save(@tmppath) end end end refute File.exists?(@tmppath) end end image_science-1.2.2/Rakefile0000444000004100000410000000057511734360156015777 0ustar www-datawww-data# -*- ruby -*- require 'rubygems' require 'hoe' Hoe.add_include_dirs("../../RubyInline/dev/lib", "../../ZenTest/dev/lib") Hoe.plugin :seattlerb Hoe.plugin :inline Hoe.spec 'image_science' do developer 'Ryan Davis', 'ryand-ruby@zenspider.com' self.rubyforge_name = 'seattlerb' clean_globs << 'blah*png' << 'images/*_thumb.*' end # vim: syntax=Ruby image_science-1.2.2/History.txt0000444000004100000410000000423111734360156016525 0ustar www-datawww-data=== 1.2.2 / 2012-03-13 * 1 minor enhancement: * Extended build to look for homebrew setup (hcatlin) * 2 bug fixes: * Fixed 1.9 warnings, clang warnings, etc... * Fixed compilation error when ruby's config mandates C89 style decls. (nocode) === 1.2.1 / 2009-08-14 * 2 minor enhancements: * Added luis' patches to make it build properly on windows. * with_image now raises on missing/bad files. == 1.2.0 / 2009-06-23 * 7 minor enhancements: * Moved quick_thumb to bin/image_science_thumb and properly added. * Added -s (square) flag to bin/image_science_thumb * Added autorotating on image load. (choonkeat) * Added ruby_inline to clean globs * Added with_image_from_memory. (sumbach) * Switched to minitest. * Updated rakefile for now hoe capabilities. * 3 bug fixes: * Check and convert to 24 BPP if save type is jpg. Caused by 32bpp png to jpg. * Fixed 1.9isms * Fixed BMP support. Tweaked whitespace. == 1.1.3 / 2007-05-30 * 2 minor enhancements: * Added quick_thumb as an example to look at. * Error handler doesn't raise by default. Raises if $DEBUG==true. == 1.1.2 / 2007-04-18 * 2 bug fixes: * reports bad height/width values for resize * explicitly removes ICC color profiles from PNGs (bug in freeimage). == 1.1.1 / 2007-03-08 * 5 minor enhancements: * Added error handler that raises with information about what went wrong. * thumbnail is now pure ruby, everything now uses resize. * Produces cleaner JPEG files, with a small cost to file size/speed. * resize now uses Catmull-Rom spline filter for better quality. * resize copies existing ICC Profile to thumbnail, producing better color. * ICC Profile NOT copied for PNG as it seems to be buggy. * 1 bug fix: * Fixed rdoc == 1.1.0 / 2007-01-05 * 3 major enhancements: * Added resize(width, height) * Added save(path) * All thumbnail and resize methods yield instead of saving directly. * 1 minor enhancement: * Will now try to use FreeImage from ports if /opt/local exists. * 2 bug fixes: * Fixed the linker issue on PPC. * Rakefile will now clean the image files created by bench.rb == 1.0.0 / 2006-12-01 * 1 major enhancement * Birthday! image_science-1.2.2/.gemtest0000644000004100000410000000000011734360156015764 0ustar www-datawww-dataimage_science-1.2.2/bin/0000755000004100000410000000000011734360156015075 5ustar www-datawww-dataimage_science-1.2.2/bin/image_science_thumb0000555000004100000410000000132511734360156020774 0ustar www-datawww-data#!/usr/local/bin/ruby -ws $s ||= false abort "#{File.basename $0} max_length files..." unless ARGV.size > 1 require 'rubygems' require 'image_science' max_length = ARGV.shift.to_i msg = $s ? :cropped_thumbnail : :thumbnail ARGV.each do |file| begin result = ImageScience.with_image file do |img| begin img.send(msg, max_length) do |thumb| # add _thumb and switch from gif to png. Really. gif just sucks. out = file.sub(/(\.[^\.]+)$/, '_thumb\1').sub(/gif$/, 'png') thumb.save(out) end rescue => e warn "Exception thumbnailing #{file}: #{e}" end end p file => result rescue => e warn "Exception opening #{file}: #{e}" end end image_science-1.2.2/metadata.yml0000644000004100000410000001026411734360156016633 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: image_science version: !ruby/object:Gem::Version hash: 27 prerelease: segments: - 1 - 2 - 2 version: 1.2.2 platform: ruby authors: - Ryan Davis autorequire: bindir: bin cert_chain: - | -----BEGIN CERTIFICATE----- MIIDPjCCAiagAwIBAgIBADANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB GRYDY29tMB4XDTA5MDMwNjE4NTMxNVoXDTEwMDMwNjE4NTMxNVowRTETMBEGA1UE AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx taCPaLmfYIaFcHHCSY4hYDJijRQkLxPeB3xbOfzfLoBDbjvx5JxgJxUjmGa7xhcT oOvjtt5P8+GSK9zLzxQP0gVLS/D0FmoE44XuDr3iQkVS2ujU5zZL84mMNqNB1znh GiadM9GHRaDiaxuX0cIUBj19T01mVE2iymf9I6bEsiayK/n6QujtyCbTWsAS9Rqt qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBBQUAA4IB AQAY59gYvDxqSqgC92nAP9P8dnGgfZgLxP237xS6XxFGJSghdz/nI6pusfCWKM8m vzjjH2wUMSSf3tNudQ3rCGLf2epkcU13/rguI88wO6MrE0wi4ZqLQX+eZQFskJb/ w6x9W1ur8eR01s397LSMexySDBrJOh34cm2AlfKr/jokKCTwcM0OvVZnAutaovC0 l1SVZ0ecg88bsWHA0Yhh7NFxK1utWoIhtB6AFC/+trM0FQEB/jZkIS8SaNzn96Rl n0sZEf77FLf5peR8TP/PtmIg7Cyqz23sLM4mCOoTGIy5OcZ8TdyiyINUHtb5ej/T FBHgymkyj/AOSqKRIpXPhjC6 -----END CERTIFICATE----- date: 2012-03-13 00:00:00 Z dependencies: - !ruby/object:Gem::Dependency name: RubyInline prerelease: false requirement: &id001 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 21 segments: - 3 - 9 version: "3.9" type: :runtime version_requirements: *id001 - !ruby/object:Gem::Dependency name: minitest prerelease: false requirement: &id002 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 21 segments: - 2 - 11 version: "2.11" type: :development version_requirements: *id002 - !ruby/object:Gem::Dependency name: rdoc prerelease: false requirement: &id003 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 19 segments: - 3 - 10 version: "3.10" type: :development version_requirements: *id003 - !ruby/object:Gem::Dependency name: hoe prerelease: false requirement: &id004 !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version hash: 29 segments: - 2 - 15 version: "2.15" type: :development version_requirements: *id004 description: |- ImageScience is a clean and happy Ruby library that generates thumbnails -- and kicks the living crap out of RMagick. Oh, and it doesn't leak memory like a sieve. :) For more information including build steps, see http://seattlerb.rubyforge.org/ email: - ryand-ruby@zenspider.com executables: - image_science_thumb extensions: [] extra_rdoc_files: - History.txt - Manifest.txt - README.txt files: - History.txt - Manifest.txt - README.txt - Rakefile - bench.rb - bin/image_science_thumb - lib/image_science.rb - test/pix.png - test/test_image_science.rb - .gemtest homepage: http://seattlerb.rubyforge.org/ImageScience.html licenses: [] post_install_message: rdoc_options: - --main - README.txt require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ">=" - !ruby/object:Gem::Version hash: 3 segments: - 0 version: "0" requirements: [] rubyforge_project: seattlerb rubygems_version: 1.8.12 signing_key: specification_version: 3 summary: ImageScience is a clean and happy Ruby library that generates thumbnails -- and kicks the living crap out of RMagick test_files: - test/test_image_science.rb image_science-1.2.2/metadata.gz.sig0000644000004100000410000000040011734360156017222 0ustar www-datawww-dataW[QG4$2 /ɺStK_)Y Zw7~$ao`s](>M~pcm' :ڹDҰ u#@€}ց p;T"(m(XHX$w, YE'z$R9:bm&pV%{(}Jlޗ#wjr?ʮ ShX%|Q}lթS'j ܳsP;zj.&{/'0,#image_science-1.2.2/bench.rb0000555000004100000410000000247211734360156015737 0ustar www-datawww-data#!/usr/local/bin/ruby -w require 'benchmark' require 'rubygems' require 'image_science' max = (ARGV.shift || 100).to_i ext = ARGV.shift || "png" file = "blah_big.#{ext}" if RUBY_PLATFORM =~ /darwin/ then # how fucking cool is this??? puts "taking screenshot for thumbnailing benchmarks" system "screencapture -SC #{file}" else abort "You need to plonk down #{file} or buy a mac" end unless test ?f, "#{file}" ImageScience.with_image(file.sub(/#{ext}$/, 'png')) do |img| img.save(file) end if ext != "png" puts "# of iterations = #{max}" Benchmark::bm(20) do |x| x.report("null_time") { for i in 0..max do # do nothing end } x.report("cropped") { for i in 0..max do ImageScience.with_image(file) do |img| img.cropped_thumbnail(100) do |thumb| thumb.save("blah_cropped.#{ext}") end end end } x.report("proportional") { for i in 0..max do ImageScience.with_image(file) do |img| img.thumbnail(100) do |thumb| thumb.save("blah_thumb.#{ext}") end end end } x.report("resize") { for i in 0..max do ImageScience.with_image(file) do |img| img.resize(200, 200) do |resize| resize.save("blah_resize.#{ext}") end end end } end # File.unlink(*Dir["blah*#{ext}"]) image_science-1.2.2/Manifest.txt0000444000004100000410000000021311734360156016626 0ustar www-datawww-dataHistory.txt Manifest.txt README.txt Rakefile bench.rb bin/image_science_thumb lib/image_science.rb test/pix.png test/test_image_science.rb image_science-1.2.2/data.tar.gz.sig0000644000004100000410000000040011734360156017140 0ustar www-datawww-datasOP/⩔C$ ^od7SF\Tb㰫E#%pY콞Q [ {Dva֜RfTrÕ9:v O}# 맀 3gnTC0r;L;lͳQ5epDn:BR\r&VEeOĐ*ʀyvCx-W8u Sf;#~|'s  E:Wimage_science-1.2.2/README.txt0000444000004100000410000000417211734360156016025 0ustar www-datawww-data= ImageScience * http://seattlerb.rubyforge.org/ImageScience.html * http://rubyforge.org/projects/seattlerb == DESCRIPTION: ImageScience is a clean and happy Ruby library that generates thumbnails -- and kicks the living crap out of RMagick. Oh, and it doesn't leak memory like a sieve. :) For more information including build steps, see http://seattlerb.rubyforge.org/ == FEATURES/PROBLEMS: * Glorious graphics manipulation magi... errr, SCIENCE! in less than 300 LoC! * Supports square and proportional thumbnails, as well as arbitrary resizes. * Pretty much any graphics format you could want. No really. == SYNOPSYS: ImageScience.with_image file do |img| img.cropped_thumbnail 100 do |thumb| thumb.save "#{file}_cropped.png" end img.thumbnail 100 do |thumb| thumb.save "#{file}_thumb.png" end end == REQUIREMENTS: * FreeImage * ImageScience == INSTALL: * Download and install FreeImage. See notes at url above. * sudo gem install -y image_science * see http://seattlerb.rubyforge.org/ImageScience.html for more info. == LICENSE: (The MIT License) Copyright (c) 2006-2009 Ryan Davis, Seattle.rb Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. image_science-1.2.2/lib/0000755000004100000410000000000011734360156015073 5ustar www-datawww-dataimage_science-1.2.2/lib/image_science.rb0000555000004100000410000002116511734360156020201 0ustar www-datawww-data#!/usr/local/bin/ruby -w require 'rubygems' require 'inline' ## # Provides a clean and simple API to generate thumbnails using # FreeImage as the underlying mechanism. # # For more information or if you have build issues with FreeImage, see # http://seattlerb.rubyforge.org/ImageScience.html class ImageScience VERSION = '1.2.2' ## # The top-level image loader opens +path+ and then yields the image. # # :singleton-method: with_image ## # The top-level image loader, opens an image from the string +data+ # and then yields the image. # # :singleton-method: with_image_from_memory ## # Crops an image to +left+, +top+, +right+, and +bottom+ and then # yields the new image. # # :method: with_crop ## # Returns the width of the image, in pixels. # # :method: width ## # Returns the height of the image, in pixels. # # :method: height ## # Saves the image out to +path+. Changing the file extension will # convert the file type to the appropriate format. # # :method: save ## # Resizes the image to +width+ and +height+ using a cubic-bspline # filter and yields the new image. # # :method: resize ## # Creates a proportional thumbnail of the image scaled so its longest # edge is resized to +size+ and yields the new image. def thumbnail(size) # :yields: image w, h = width, height scale = size.to_f / (w > h ? w : h) self.resize((w * scale).to_i, (h * scale).to_i) do |image| yield image end end ## # Creates a square thumbnail of the image cropping the longest edge # to match the shortest edge, resizes to +size+, and yields the new # image. def cropped_thumbnail(size) # :yields: image w, h = width, height l, t, r, b, half = 0, 0, w, h, (w - h).abs / 2 l, r = half, half + h if w > h t, b = half, half + w if h > w with_crop(l, t, r, b) do |img| img.thumbnail(size) do |thumb| yield thumb end end end inline do |builder| %w[/opt/local /usr/local].each do |dir| if File.directory? "#{dir}/include" then builder.add_compile_flags "-I#{dir}/include" builder.add_link_flags "-L#{dir}/lib" end end builder.add_link_flags "-lfreeimage" unless RUBY_PLATFORM =~ /mswin/ builder.add_link_flags "-lfreeimage" # TODO: detect PPC builder.add_link_flags "-lstdc++" # only needed on PPC for some reason else builder.add_link_flags "freeimage.lib" end builder.include '"FreeImage.h"' builder.prefix <<-"END" #define GET_BITMAP(name) Data_Get_Struct(self, FIBITMAP, (name)); if (!(name)) rb_raise(rb_eTypeError, "Bitmap has already been freed"); END builder.prefix <<-"END" VALUE unload(VALUE self) { FIBITMAP *bitmap; GET_BITMAP(bitmap); FreeImage_Unload(bitmap); DATA_PTR(self) = NULL; return Qnil; } END builder.prefix <<-"END" VALUE wrap_and_yield(FIBITMAP *image, VALUE self, FREE_IMAGE_FORMAT fif) { unsigned int self_is_class = rb_type(self) == T_CLASS; VALUE klass = self_is_class ? self : CLASS_OF(self); VALUE type = self_is_class ? INT2FIX(fif) : rb_iv_get(self, "@file_type"); VALUE obj = Data_Wrap_Struct(klass, NULL, NULL, image); rb_iv_set(obj, "@file_type", type); return rb_ensure(rb_yield, obj, unload, obj); } END builder.prefix <<-"END" void copy_icc_profile(VALUE self, FIBITMAP *from, FIBITMAP *to) { FREE_IMAGE_FORMAT fif = FIX2INT(rb_iv_get(self, "@file_type")); if (fif != FIF_PNG && FreeImage_FIFSupportsICCProfiles(fif)) { FIICCPROFILE *profile = FreeImage_GetICCProfile(from); if (profile && profile->data) { FreeImage_CreateICCProfile(to, profile->data, profile->size); } } } END builder.prefix <<-"END" void FreeImageErrorHandler(FREE_IMAGE_FORMAT fif, const char *message) { rb_raise(rb_eRuntimeError, "FreeImage exception for type %s: %s", (fif == FIF_UNKNOWN) ? "???" : FreeImage_GetFormatFromFIF(fif), message); } END builder.add_to_init "FreeImage_SetOutputMessage(FreeImageErrorHandler);" builder.c_singleton <<-"END" VALUE with_image(char * input) { FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; int flags; fif = FreeImage_GetFileType(input, 0); if (fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilename(input); if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) { FIBITMAP *bitmap; VALUE result = Qnil; flags = fif == FIF_JPEG ? JPEG_ACCURATE : 0; if ((bitmap = FreeImage_Load(fif, input, flags))) { FITAG *tagValue = NULL; FreeImage_GetMetadata(FIMD_EXIF_MAIN, bitmap, "Orientation", &tagValue); switch (tagValue == NULL ? 0 : *((short *) FreeImage_GetTagValue(tagValue))) { case 6: bitmap = FreeImage_RotateClassic(bitmap, 270); break; case 3: bitmap = FreeImage_RotateClassic(bitmap, 180); break; case 8: bitmap = FreeImage_RotateClassic(bitmap, 90); break; default: break; } result = wrap_and_yield(bitmap, self, fif); } return result; } rb_raise(rb_eTypeError, "Unknown file format"); return Qnil; } END builder.c_singleton <<-"END" VALUE with_image_from_memory(VALUE image_data) { FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; BYTE *image_data_ptr; DWORD image_data_length; FIMEMORY *stream; FIBITMAP *bitmap = NULL; VALUE result = Qnil; int flags; Check_Type(image_data, T_STRING); image_data_ptr = (BYTE*)RSTRING_PTR(image_data); image_data_length = (DWORD)RSTRING_LEN(image_data); stream = FreeImage_OpenMemory(image_data_ptr, image_data_length); if (NULL == stream) { rb_raise(rb_eTypeError, "Unable to open image_data"); } fif = FreeImage_GetFileTypeFromMemory(stream, 0); if ((fif == FIF_UNKNOWN) || !FreeImage_FIFSupportsReading(fif)) { rb_raise(rb_eTypeError, "Unknown file format"); } flags = fif == FIF_JPEG ? JPEG_ACCURATE : 0; bitmap = FreeImage_LoadFromMemory(fif, stream, flags); FreeImage_CloseMemory(stream); if (bitmap) { result = wrap_and_yield(bitmap, self, fif); } return result; } END builder.c <<-"END" VALUE with_crop(int l, int t, int r, int b) { FIBITMAP *copy, *bitmap; VALUE result = Qnil; GET_BITMAP(bitmap); if ((copy = FreeImage_Copy(bitmap, l, t, r, b))) { copy_icc_profile(self, bitmap, copy); result = wrap_and_yield(copy, self, 0); } return result; } END builder.c <<-"END" int height() { FIBITMAP *bitmap; GET_BITMAP(bitmap); return FreeImage_GetHeight(bitmap); } END builder.c <<-"END" int width() { FIBITMAP *bitmap; GET_BITMAP(bitmap); return FreeImage_GetWidth(bitmap); } END builder.c <<-"END" VALUE resize(int w, int h) { FIBITMAP *bitmap, *image; if (w <= 0) rb_raise(rb_eArgError, "Width <= 0"); if (h <= 0) rb_raise(rb_eArgError, "Height <= 0"); GET_BITMAP(bitmap); image = FreeImage_Rescale(bitmap, w, h, FILTER_CATMULLROM); if (image) { copy_icc_profile(self, bitmap, image); return wrap_and_yield(image, self, 0); } return Qnil; } END builder.c <<-"END" VALUE save(char * output) { int flags; FIBITMAP *bitmap; FREE_IMAGE_FORMAT fif = FreeImage_GetFIFFromFilename(output); if (fif == FIF_UNKNOWN) fif = FIX2INT(rb_iv_get(self, "@file_type")); if ((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsWriting(fif)) { BOOL result = 0, unload = 0; GET_BITMAP(bitmap); flags = fif == FIF_JPEG ? JPEG_QUALITYSUPERB : 0; if (fif == FIF_PNG) FreeImage_DestroyICCProfile(bitmap); if (fif == FIF_JPEG && FreeImage_GetBPP(bitmap) != 24) bitmap = FreeImage_ConvertTo24Bits(bitmap), unload = 1; // sue me result = FreeImage_Save(fif, bitmap, output, flags); if (unload) FreeImage_Unload(bitmap); return result ? Qtrue : Qfalse; } rb_raise(rb_eTypeError, "Unknown file format"); return Qnil; } END end end