Module: ImagesHelper

Defined in:
app/helpers/images_helper.rb

Instance Method Summary collapse

Instance Method Details

#image_autocomplete_tag(image) ⇒ Object



52
53
54
55
56
57
58
59
# File 'app/helpers/images_helper.rb', line 52

def image_autocomplete_tag(image)
  (:figure) do
    (
      image_tag(image.image_file.url(:thumb)) +
      (:caption, "id:#{image.id}", class: ['feedback', 'feedback-primary', 'feedback-thin']) 
    ).html_safe
  end
end

#image_display_url(image) ⇒ Object



71
72
73
74
75
76
77
78
# File 'app/helpers/images_helper.rb', line 71

def image_display_url(image)
  case image.image_file_content_type
  when 'image/tiff'
    "/images/#{image.id}/extract/0/0/#{image.width}/#{image.height}"
  else
    root_url + image.image_file.url[1..-1]
  end
end

!! Rails already provides image_tag, i.e. it is not required here.



5
6
7
8
# File 'app/helpers/images_helper.rb', line 5

def image_link(image, size: :thumb)
  return nil if image.nil?
  link_to(image_tag(image.image_file.url(size)), image)
end

#image_short_url(image, api: true) ⇒ Object

Return a ShortenedUrl to the original file image



34
35
36
37
38
39
40
41
42
43
44
# File 'app/helpers/images_helper.rb', line 34

def image_short_url(image, api: true)
  if !image.kind_of?(::Image) && (Integer(image) rescue false)
    image = ::Image.find(image)
  end

  if api
    short_url( api_v1_image_file_path( image) )
  else
    short_url( image.image_file.url(:original) )
  end
end

#image_type(image) ⇒ String

Returns like ‘jpeg`, `png`.

Returns:

  • (String)

    like ‘jpeg`, `png`



16
17
18
# File 'app/helpers/images_helper.rb', line 16

def image_type(image)
  image.image_file.content_type.split('/').last.downcase
end

#images_recent_objects_partialTrue

Returns indicates a custom partial should be used, see list_helper.rb.

Returns:

  • (True)

    indicates a custom partial should be used, see list_helper.rb



48
49
50
# File 'app/helpers/images_helper.rb', line 48

def images_recent_objects_partial
  true 
end

#images_search_formObject



10
11
12
# File 'app/helpers/images_helper.rb', line 10

def images_search_form
  render('/images/quick_search_form')
end

#original_as_png_via_api(image, api: true) ⇒ Object

“/images/scale_to_box/:x/:y/:width/:height/:box_width/:box_height”



22
23
24
25
26
27
28
29
30
# File 'app/helpers/images_helper.rb', line 22

def original_as_png_via_api(image, api: true)
 h = image.height
 w = image.width 

 s = api ? '/api/v1' : ''

 s << "/images/#{image.id}/scale_to_box/0/0/#{w}/#{h}/#{w}/#{h}"
 s
end

#thumb_list_tag(object) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'app/helpers/images_helper.rb', line 61

def thumb_list_tag(object)
  if object.depictions.any?
    object.depictions.collect{|a|
      (:div)  do
        link_to( depiction_tag(a, size: :medium), a.image.image_file.url())
      end
    }.join.html_safe
  end
end