1007 |
1007 |
title_and_alt = other_attrs.scan(title_and_alt_re).to_h
|
1008 |
1008 |
other_attrs.gsub!(title_and_alt_re, '')
|
1009 |
1009 |
|
1010 |
|
# Process dimensions and scaling
|
1011 |
|
width, height = nil, nil
|
1012 |
|
image = MiniMagick::Image.open(found.diskfile)
|
1013 |
|
width, height = image.width, image.height
|
1014 |
|
|
1015 |
|
# Adjust dimensions for @2x, @3x, etc.
|
1016 |
|
if filename =~ /@(\d+)x\./
|
1017 |
|
scale_factor = $1.to_i
|
1018 |
|
width /= scale_factor
|
1019 |
|
height /= scale_factor
|
1020 |
|
end
|
|
1010 |
# Get cache store configuration
|
|
1011 |
config = Rails.application.config.redmine_image_cache_store rescue :memory_store
|
|
1012 |
cache_store = ActiveSupport::Cache.lookup_store(config)
|
|
1013 |
|
|
1014 |
# Use digest from the database as cache key
|
|
1015 |
cache_key = "image_dimensions:#{found.digest}"
|
|
1016 |
|
|
1017 |
# Cache dimensions and retrieve from Redis or memory store
|
|
1018 |
dimensions = cache_store.fetch(cache_key) do
|
|
1019 |
# Process dimensions and scaling
|
|
1020 |
image = MiniMagick::Image.open(found.diskfile)
|
|
1021 |
width, height = image.width, image.height
|
|
1022 |
|
|
1023 |
# Adjust dimensions for @2x, @3x, etc.
|
|
1024 |
if filename =~ /@(\d+)x\./
|
|
1025 |
scale_factor = $1.to_i
|
|
1026 |
width /= scale_factor
|
|
1027 |
height /= scale_factor
|
|
1028 |
end
|
1021 |
1029 |
|
1022 |
|
# Resize if width exceeds 1000px while maintaining aspect ratio
|
1023 |
|
if width > 1000
|
1024 |
|
scale = 800.0 / width
|
1025 |
|
width = 800
|
1026 |
|
height = (height * scale).round
|
|
1030 |
# Resize if width exceeds 1000px while maintaining aspect ratio
|
|
1031 |
if width > 1000
|
|
1032 |
scale = 800.0 / width
|
|
1033 |
width = 800
|
|
1034 |
height = (height * scale).round
|
|
1035 |
end
|
|
1036 |
|
|
1037 |
{ width: width, height: height }
|
1027 |
1038 |
end
|
1028 |
1039 |
|
|
1040 |
width = dimensions[:width]
|
|
1041 |
height = dimensions[:height]
|
|
1042 |
|
1029 |
1043 |
# Add width and height to the img tag only if style attribute is absent
|
1030 |
1044 |
dimension_attrs = (!has_style && width && height) ? " width=\"#{width}\" height=\"#{height}\"" : ""
|
1031 |
1045 |
|