lib/co-kamishibai/functions.rb
# all done in memory, but gives seg fault on some condition, png file for eg
all done in memory, but gives seg fault on some condition, png file for eg
all done in memory but gives seg fault on some condition png file for eg
def img_resize( dat, w, h, options = {} )
  quality = options[:quality]
  format = options[:format]
  begin
    img = GD2::Image.load(dat)
    if h == 0
      h = ( w / img.aspect ).to_i
    end
    puts "resizing image… width: #{w}, height: #{h}, quality: #{quality}" if $debug
    res = img.size
    if res[0] < w and res[1] < h
      w = res[0]
      h = res[1]
    elsif res[0] < w
      w = res[0]
      h = (w / img.aspect).to_i
    elsif res[1] < h
      h = res[1]
      w = (h / img.aspect).to_i
    end
    nimg = img.resize( w, h )
    if img_type(dat) == :jpeg and quality
      nimg.jpeg( quality.to_i )
    else
      case img_type(dat)
        when :png
          nimg.png
        when :jpeg
          nimg.jpeg
        when :gif
          nimg.gif
        else
          raise 'img_resize(), unknown output format'
      end
    end
  rescue => errmsg
    puts "error: resize failed. #{w} #{h} #{quality}"
    p errmsg
    return nil
  end
end
def img_resize ( dat , w , h , options = { } ) quality = options [ :quality ] format = options [ :format ] begin img = GD2 :: Image . load ( dat ) if h == 0 h = ( w / img . aspect ) . to_i end puts "resizing image… width: #{w}, height: #{h}, quality: #{quality}" i  $ ebug res = img . size if res [ 0 ] < w and res [ 1 ] < h w = res [ 0 ] h = res [ 1 ] elsif res [ 0 ] < w w = res [ 0 ] h = ( w / img . aspect ) . to_i elsif res [ 1 ] < h h = res [ 1 ] w = ( h / img . aspect ) . to_i end nimg = img . resize ( w , h ) if img_type ( dat ) == :jpeg and quality nimg . jpeg ( quality . to_i ) else case img_type ( dat ) when :png nimg . png when :jpeg nimg . jpeg when :gif nimg . gif else raise 'img_resize(), unknown output format' end end rescue => errmsg puts "error: resize failed. #{w} #{h} #{quality}" p errmsg return nil end end
all done in memory, but gives seg fault on some condition, png file for eg
all done in memory but gives seg fault on some condition png file for eg
# make sure it doesn't upscale image
dat
w
h
options