0

what I'd like to do is very simple. I have a code which uses a imgkit library to load some webpage image and then stores it. It looks like that:

kit = IMGKit.new(site, :quality => 5, :width => 1024)
img = kit.to_img(:png)
file = kit.to_file("#{Rails.root}/public/images/#{s2}.png")

I need to know the image height after loading in order to stretch canvas element behind it. Is there a way I can get the height ? Or if not, how could I achieve this without knowing the image height before loading, javascript ?

user2229608
  • 45
  • 1
  • 9

2 Answers2

0

relevant question,

Would following work?

kit = IMGKit.new(site, :quality => 5, :width => 1024)
img = kit.to_img(:png)
file = kit.to_file("#{Rails.root}/public/images/#{s2}.png")  

var img2 = new Image();       
img2.onload = function(){
  var height = img2.height;

  //do all remaining processing here

};
img2.src = file;
user5226582
  • 1,946
  • 1
  • 22
  • 37
  • i forgot to add that i use rails, you mixed code from rails and js into one... maybe i could get the height using minimagick_gem, but I have not yet tried – user2229608 Apr 08 '16 at 12:10
0

Ok, I've figured it out. Mini_magick gem was a fine way how to do this.

user2229608
  • 45
  • 1
  • 9