Project

General

Profile

Patch #43932 ยป Add-HEIC-HEIF-image-support.patch

Peter Petrik, 2026-04-06 14:18

View differences:

app/models/attachment.rb
220 220
  end
221 221
  def image?
222
    !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|webp)$/i)
222
    !!(self.filename =~ /\.(bmp|gif|jpg|jpe|jpeg|png|webp|heic|heif)$/i)
223 223
  end
224 224
  def thumbnailable?
225
-- a/app/helpers/application_helper.rb
225
++ b/app/helpers/application_helper.rb
......
999 999
    if attachments.present?
1000 1000
      title_and_alt_re = /\s+(title|alt)="([^"]*)"/i
1001
      text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png|webp))"([^>]*)/i) do |m|
1001
      text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpe|jpeg|png|webp|heic|heif))"([^>]*)/i) do |m|
1002 1002
        filename, ext, other_attrs = $1, $2, $3
1003 1003
        # search for the picture in attachments
1004
-- a/lib/redmine/thumbnail.rb
1004
++ b/lib/redmine/thumbnail.rb
......
30 30
      ('gswin64c' if Redmine::Platform.mswin?) ||
31 31
      'gs'
32 32
    ).freeze
33
    ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png image/webp application/pdf)
33
    ALLOWED_TYPES = %w(image/bmp image/gif image/jpeg image/png image/webp image/heic image/heif application/pdf)
34 34
    # Generates a thumbnail for the source image to target
35 35
    # TODO: Remove the deprecated _is_pdf parameter in Redmine 7.0
......
51 51
          return nil unless valid_pdf_magic?(source)
52 52
          cmd = "#{shell_quote CONVERT_BIN} #{shell_quote "#{source}[0]"} -thumbnail #{shell_quote size_option} #{shell_quote "png:#{target}"}"
53
        elsif mime_type == 'image/heic' || mime_type == 'image/heif'
54
          cmd = "#{shell_quote CONVERT_BIN} #{shell_quote source} -auto-orient -thumbnail #{shell_quote size_option} #{shell_quote "jpg:#{target}"}"
53 55
        else
54 56
          cmd = "#{shell_quote CONVERT_BIN} #{shell_quote source} -auto-orient -thumbnail #{shell_quote size_option} #{shell_quote target}"
55 57
        end
56
-- a/app/controllers/attachments_controller.rb
58
++ b/app/controllers/attachments_controller.rb
......
294 294
    if is_thumb && content_type == "application/pdf"
295 295
      # PDF previews are stored in PNG format
296 296
      content_type = "image/png"
297
    elsif is_thumb && (content_type == "image/heic" || content_type == "image/heif")
298
      # HEIC/HEIF previews are stored in JPEG format
299
      content_type = "image/jpeg"
297 300
    end
298 301
    content_type
    (1-1/1)