-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #453 from codeforjapan/develop
feat: add support for heic format
- Loading branch information
Showing
19 changed files
with
218 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class HeicPreviewer < ActiveStorage::Previewer | ||
CONTENT_TYPES = %w(image/heic image/heif image/heic-sequence image/heif-sequence).freeze | ||
|
||
class << self | ||
def accept?(blob) | ||
CONTENT_TYPES.include?(blob.content_type) && minimagick_exists? | ||
end | ||
|
||
def minimagick_exists? | ||
return @minimagick_exists if @minimagick_exists.present? | ||
|
||
@minimagick_exists = defined?(ImageProcessing::MiniMagick) | ||
Rails.logger.error "#{self.class} :: MiniMagick is not installed" unless @minimagick_exists | ||
|
||
@minimagick_exists | ||
end | ||
end | ||
|
||
def preview(**_options) | ||
download_blob_to_tempfile do |input| | ||
begin | ||
io = ImageProcessing::MiniMagick.source(input).convert("png").call | ||
rescue ImageProcessing::Error | ||
io = ImageProcessing::MiniMagick.loader(page: 0).source(input).convert("png").call | ||
end | ||
yield io: io, filename: "#{blob.filename.base}.png", content_type: "image/png" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
Rails.application.configure do | ||
config.active_storage.previewers << HeicPreviewer | ||
config.active_storage.variable_content_types << "image/heic" | ||
config.active_storage.variable_content_types << "image/heif" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.