Module: JekyllIS::Images::Image::SEO
- Extended by:
- SEO
- Included in:
- JekyllIS::Images::Image, SEO
- Defined in:
- lib/jekyll-is/images/image/seo.rb
Instance Method Summary collapse
Methods included from Magick
#magick_convert, #magick_generate
Methods included from Cache
#cached_file, #clean_unused_files, #magick_image, #restore_static_files, #source_digest, #static_info
Instance Method Details
#replace_page_image(site, page) ⇒ void
This method returns an undefined value.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/jekyll-is/images/image/seo.rb', line 21 def replace_page_image site, page source = page.data['image'] return source if source == nil || source.empty? || source.start_with?('/') context = JekyllIS::Images::Context[site, page] format = context.config(IMAGE_PARAMS, 'format') crop = context.config(IMAGE_PARAMS, 'crop') width = context.config(IMAGE_PARAMS, 'width')&.to_i height = context.config(IMAGE_PARAMS, 'height')&.to_i = context.config(IMAGE_PARAMS, 'overlay', 'width')&.to_i bottom_height = context.config(IMAGE_PARAMS, 'overlay', 'bottom')&.to_i top_height = context.config(IMAGE_PARAMS, 'overlay', 'top')&.to_i padding = context.config(IMAGE_PARAMS, 'overlay', 'padding')&.to_i = context.config(IMAGE_PARAMS, 'overlay', 'background') = context.config(IMAGE_PARAMS, 'overlay', 'foreground') caption_font = context.config(IMAGE_PARAMS, 'font', 'caption') date_font = context.config(IMAGE_PARAMS, 'font', 'date') || caption_font date_font_size = context.config(IMAGE_PARAMS, 'font', 'date_size') || 24 site_font = context.config(IMAGE_PARAMS, 'font', 'site') || date_font site_font_size = context.config(IMAGE_PARAMS, 'font', 'site_size') || date_font_size salt = context.config(IMAGE_PARAMS, 'salt') caption = context.config(IMAGE_PARAMS, 'caption') || page.data['title'] site_title = context.config(IMAGE_PARAMS, 'site') || site.config['title'] date = context.config(IMAGE_PARAMS, 'date') || page.data['date'] date_format = context.config(IMAGE_PARAMS, 'date_format') || '%Y-%m-%d' date = date.strftime date_format if date.is_a?(Time) || date.is_a?(Date) = context. format params = { format:, crop:, width:, height:, overlay_width:, bottom_height:, top_height:, padding:, overlay_background:, overlay_foreground:, caption_font:, date_font:, date_font_size:, site_font:, site_font_size:, salt:, caption:, site: site_title, date:, date_format:, options: } digest = source_digest(context, source, **params) info = static_info context, digest, params[:format] do |full| begin base = base_image context, source, params base. do |img| img.repage '+0+0' img.gravity 'Center' img.extent "#{ width }:#{ height }" img.resize "#{ width }x#{ height }" end bottom = background_image context, params[:bottom_height], params result = base.composite bottom do |img| img.gravity 'South' img.geometry "+0+#{ params[:padding] }" end caption_img = caption_image context, params result = result.composite caption_img do |img| img.gravity 'South' img.geometry "+0+#{ 2 * params[:padding] }" end top = background_image context, params[:top_height], params result = result.composite top do |img| img.gravity 'North' img.geometry "+0+#{ params[:padding] }" end = context, params result = result.composite do |img| img.gravity 'North' img.geometry "+0+#{ params[:padding] }" end result.format format result.strip result.write full ensure base&.destroy! bottom&.destroy! caption_img&.destroy! top&.destroy! &.destroy! result&.destroy! end end page.data['image'] = info.url return info.url end |