Giter VIP home page Giter VIP logo

image_science's Introduction

= ImageScience

home :: https://github.com/seattlerb/image_science
bugs :: https://github.com/seattlerb/image_science/issues
rdoc :: https://docs.seattlerb.org/image_science

== 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, see https://docs.seattlerb.org/image_science

== 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.

== SYNOPSIS:

  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 https://docs.seattlerb.org/image_science 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's People

Contributors

zenspider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

image_science's Issues

raising error on warnings

https://f.cloud.github.com/assets/26167/962446/027b0198-04f0-11e3-9c07-3bae19ce7608.jpg

When trying to process this image, we get an error raised:

RuntimeError: FreeImage exception for type JPEG: Corrupt JPEG data: 49 extraneous bytes before marker 0xd9

if I comment out this line

https://github.com/seattlerb/image_science/blob/master/lib/image_science.rb#L176

it works.

I don't know how to link to the FreeImage source, but it looks like that message is coming from here:

Source/LibJPEG/jdmarker.c:946
WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);

which looks like it should be a warning and not an error.
do you have any thoughts? I'm still trying to find documentation for FreeImage_SetOutputMessage.

test_class_with_image_missing_with_img_extension fails

This test fails even under Ruby 1.8.7/1.9.2 without any patches
on top of commit 1816f8c

  1. Failure:
    test_class_with_image_missing_with_img_extension(TestImageScience) [../tes
    RuntimeError expected but nothing was raised.

This failure may be dependent on the version of FreeImage used,
I'm using libfreeimage 3.10.0-4+b1 in Debian testing.

Originally discovered while working on another bug, but happens
without the patch here:
http://rubyforge.org//tracker/?func=detail&atid=5923&aid=29474&group_id=1513

Add RubyInline as a dependency

inline is a dependency but the gem RubyInline isn't listed as a dependency in the gemfile (I had to set it up manually). Unless I'm mistaken it should be listed as a dependency.

Jpg compression

I need the ability to specify the jpg quality that is being saved out. Look like it is being forced to JPEG_QUALITYSUPERB. For some files JPEG_QUALITYSUPERB is perfect but for other purposes I need more compression.

Errors compiling under 1.9.3-preview1

We are getting this error when trying to start our application with image_science under 1.9.3-preview1:

/home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/bundler/gems/image_science-9b9ba4367f64/lib/image_science.rb: In function 'with_image_from_memory':
/home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/bundler/gems/image_science-9b9ba4367f64/lib/image_science.rb:209: error: ISO C90 forbids mixed declarations and code
/home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/bundler/gems/image_science-9b9ba4367f64/lib/image_science.rb:222: error: ISO C90 forbids mixed declarations and code
/home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/bundler/gems/image_science-9b9ba4367f64/lib/image_science.rb: In function 'save':
/home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/bundler/gems/image_science-9b9ba4367f64/lib/image_science.rb:290: error: ISO C90 forbids mixed declarations and code
/home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/RubyInline-3.9.0/lib/inline.rb:590:in `build': error executing "gcc -shared -I/usr/local/include  -fPIC  -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=implicit-function-declaration  -fPIC -I /home/travis/.rvm/rubies/ruby-1.9.3-preview1/include/ruby-1.9.1 -I /home/travis/.rvm/rubies/ruby-1.9.3-preview1/include/ruby-1.9.1/x86_64-linux -I /home/travis/.rvm/rubies/ruby-1.9.3-preview1/include -L/home/travis/.rvm/rubies/ruby-1.9.3-preview1/lib -o \"/home/travis/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/site_ruby/1.9.1/x86_64-linux/.ruby_inline/Inline_ImageScience_1c7c.so\" \"/home/travis/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/site_ruby/1.9.1/x86_64-linux/.ruby_inline/Inline_ImageScience_1c7c.c\" -L/usr/local/lib -lfreeimage -lfreeimage -lstdc++ ": pid 12834 exit 1 (CompilationError)
Renamed /home/travis/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/site_ruby/1.9.1/x86_64-linux/.ruby_inline/Inline_ImageScience_1c7c.c to /home/travis/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/site_ruby/1.9.1/x86_64-linux/.ruby_inline/Inline_ImageScience_1c7c.c.bad
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/RubyInline-3.9.0/lib/inline.rb:828:in `inline'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/bundler/gems/image_science-9b9ba4367f64/lib/image_science.rb:90:in `'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/bundler/gems/image_science-9b9ba4367f64/lib/image_science.rb:13:in `'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/bundler-1.0.17/lib/bundler/runtime.rb:68:in `require'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/bundler-1.0.17/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/bundler-1.0.17/lib/bundler/runtime.rb:66:in `each'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/bundler-1.0.17/lib/bundler/runtime.rb:66:in `block in require'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/bundler-1.0.17/lib/bundler/runtime.rb:55:in `each'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/bundler-1.0.17/lib/bundler/runtime.rb:55:in `require'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/bundler-1.0.17/lib/bundler.rb:120:in `require'
    from /home/travis/zerista/app/config/application.rb:34:in `'
    from /home/travis/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/travis/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/travis/zerista/app/config/environment.rb:18:in `'
    from /home/travis/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/travis/.rvm/rubies/ruby-1.9.3-preview1/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/travis/zerista/app/config.ru:1:in `block in '
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/rack-1.3.2/lib/rack/builder.rb:51:in `instance_eval'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/rack-1.3.2/lib/rack/builder.rb:51:in `initialize'
    from /home/travis/zerista/app/config.ru:1:in `new'
    from /home/travis/zerista/app/config.ru:1:in `'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/thin-1.2.11/lib/rack/adapter/loader.rb:36:in `eval'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/thin-1.2.11/lib/rack/adapter/loader.rb:36:in `load'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/thin-1.2.11/lib/rack/adapter/loader.rb:45:in `for'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/thin-1.2.11/lib/thin/controllers/controller.rb:169:in `load_adapter'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/thin-1.2.11/lib/thin/controllers/controller.rb:73:in `start'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/thin-1.2.11/lib/thin/runner.rb:185:in `run_command'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/thin-1.2.11/lib/thin/runner.rb:151:in `run!'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/gems/thin-1.2.11/bin/thin:6:in `'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/bin/thin:19:in `load'
    from /home/travis/.rvm/gems/ruby-1.9.3-preview1@zerista/bin/thin:19:in `'

Our workaround for now is to manually compile the failed file with only these switches (note, the differences in the -I switches are just because the come from different machines):

-c -fPIC -I/usr/local/rvm/rubies/ruby-1.9.3-preview1/include/ruby-1.9.1 -I/usr/local/rvm/rubies/ruby-1.9.3-preview1/include/ruby-1.9.1/x86_64-linux

I'm not sure if this is is a configuration difference or a platform difference, but on Mac OS X (Lion), these errors are only warnings, and image_science successfully compiles; however, on ArchLinux, Gentoo, and Windows they are errors and the compile fails. The success of the compile varies on CentOS.

Memory leak in ReOrient function

image_science leaks whenever the ReOrient function is called. In the following code snippet from lib/image_science.rb, the old bitmap is not being freed when the new, rotated bitmap is given to the variable.

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;
}

Here's some ruby you can run to reproduce the leak:

require 'image_science'

image = File.read('rotated_image.jpg')

1000.times do
  ImageScience.with_image_from_memory(image) { }
end

And this is the image I'm using: https://dl.dropboxusercontent.com/u/4234581/rotated_image.jpg

inline file not changed after upgrade

upgrading from 1.2.3 to 1.2.4 does not update the generated inline file. This causes the latest commit (orientation logic) to not work. This is probably a bug in rubyinline.

thoughts?

EXIF orientation problems

Hi - I've been having trouble with image_science's handling of EXIF orientation tags. It auto-rotates the image when it's loaded via with_image, which is fine. But if you then save that image, it writes the auto-rotated data, and includes the orientation tag from the original file. If you then open that file in a program that understands EXIF tags, it's going to add a further rotation to the autorotated data. Does that make sense? So if an image with a 90° CW EXIF tag passes through image_science, the resulting image will be rotated 180 ° when viewed in an exif-compatible program.

I've been looking at this and came to the conclusion that FreeImage's handling of exif tags meant it was more or less impossible to fix within image_science, since (AFAICT), they don't support writing exif tags on anything except TIFFs (http://switch.dl.sourceforge.net/project/freeimage/Source%20Documentation/3.15.3/FreeImage3153.pdf, page 72). I'm currently manually stripped the orientation tag out of our resulting images by shelling out to exiftool, but wondered if anyone else had run into this problem or had any suggestions.

[PATCH] defer raising exception until wrapped by rb_ensure

Edit: adding an additional patch to quiet a -Wformat-security warning.

It is not safe to call rb_raise() directly from FreeImageErrorHandler().
We may be deep inside FreeImage code which does not expect exceptions
and have untracked allocations which need to be freed.

Otherwise, repeatedly loading an image which triggers errors/warnings
in the following script will lead to infinite memory usage:

require 'image_science'
path = ARGV.shift or abort "Usage: #$0 BADIMAGE\n"
begin
  ImageScience.with_image(path) do |img|
    p img.class
  end
rescue => e
  p [ e.class, e.message ]
end while true

Bad image example from: #21
https://f.cloud.github.com/assets/26167/962446/027b0198-04f0-11e3-9c07-3bae19ce7608.jpg

-------------------------- 8< ------------------------------
I will not endorse github for treating repos they don't host as second class citizens:

downloadable patches here:

http://bogomips.org/image_science.git/patch/?id=3145b038258888cfb1b5cbc549ad2baa9a48b1dd
http://bogomips.org/image_science.git/patch/?id=3b0c5d6da4444f19c7a1b73ac7720d10905e0cdb

Pull request here:

The following changes since commit 5271cfe:

prepped for release [git-p4: depot-paths = "//src/image_science/dev/": change = 8704](2013-06-20 16:03:00 -0800)

are available in the git repository at:

git://bogomips.org/image_science issue-23

for you to fetch changes up to 3b0c5d6da4444f19c7a1b73ac7720d10905e0cdb:

prevent -Wformat-security warnings with rb_raise (2013-11-27 17:54:20 +0000)


Eric Wong (2):
defer raising exception until wrapped by rb_ensure
prevent -Wformat-security warnings with rb_raise

lib/image_science.rb | 39 +++++++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)

ENV['INLINEDIR'] can't be relative

I was setting ENV['INLINEDIR'] to "tmp", e.g. relative to my Rails.root, the correct files would get created, e.g. I have Inline_ImageScience_cdabbf6be1583cf10d50065dbe0df70a.so and Inline_ImageScience_cdabbf6be1583cf10d50065dbe0df70a.c in my tmp/ruby_inline/ruby-1.9.1/ folder, however rails would still fail to boot saying it can't find tmp/.ruby_inline/ruby-1.9.1/Inline_ImageScience_cdabbf6be1583cf10d50065dbe0df70a.so.

Changing my ENV['INLINEDIR'] to File.join Rails.root, 'tmp' fixed my problem. I.e. using an absolute path over a relative one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.