IMGKit icon indicating copy to clipboard operation
IMGKit copied to clipboard

Path for images in <img> tags

Open Quizot opened this issue 12 years ago • 5 comments

While embedding images with html there is an issue with mentioning image path . A path starting with "http://localhost:3000/" sends the rails server into a loop .

question = IMGKit.new('< img_tag src = 'http://localhost:3000/assets/qimage/629a3a4_1_original.jpg' />',:quality => 100)

question.to_file("/home/superq/quizot/app/assets/images/questions/test_123.jpg")

If I use an absolute path of my local machine , it works fine . However that is not a very convenient option . How should the path of the image be mentioned ? I am on Rails 3

Note : I am using img_tag above so that it is not picked up as an actual tag here.

Quizot avatar May 16 '13 07:05 Quizot

I'm having the same issue too.

leonardoafpinto avatar May 16 '13 12:05 leonardoafpinto

Did you manage to find a workaround for this yet ? I am still stuck .

Quizot avatar May 27 '13 10:05 Quizot

I'm working with absolut path too. It's not the best way, but i needed to complete the project.

leonardoafpinto avatar May 27 '13 12:05 leonardoafpinto

What about using File.expand_path to get the abslolute path?

The Gem doesn't really know whereabouts you'd like to store the file (should It be relative to RAILS_ROOT, __FILE__), etc.

Anyways, those are just my first thoughts -- leave it as an exercise for the reader. :)

csquared avatar Jun 07 '13 23:06 csquared

Workaround

<% background = File.read("#{Rails.root}/app/assets/images/backgound.png") %>
<img src="<%= 'data:image/png;base64,' + Base64.strict_encode64(background) %>" />

anaumov avatar Dec 07 '20 14:12 anaumov