You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
add_metadata :dominant_color do |io|
dominant_color(io.path)
end
I had to do this:
add_metadata :dominant_color do |io, **options|
next unless options[:background]
Shrine.with_file(io) { |file| dominant_color(file.path) }
end
With the following background worker:
class ShrinePromoteWorker < ApplicationWorker
def perform(attacher_class, record_class, record_id, name, file_data)
attacher_class = Object.const_get(attacher_class)
record = Object.const_get(record_class).find(record_id)
attacher = attacher_class.retrieve(model: record, name: name, file: file_data)
attacher.refresh_metadata!(background: true)
attacher.atomic_promote
end
end
This is after updating to the latest shrine version. The reason is io.path is not defined for UploadedFile objects. We have to ultimately download the full file to get a color from it. And best to do it in a background job.
I'm not sure but this could be a case unique to people doing direct to S3 uploads 🤷♂
The text was updated successfully, but these errors were encountered:
Also I'm not sure if it's the custom fork of colorscore that this uses or something in colorscore itself but i always ended up with puke green for many of the dominant colors.
I ended up switching to the miro gem and doing this:
add_metadata :dominant_color do |io, **options|
next unless options[:background]
Shrine.with_file(io) do |file|
Miro::DominantColors.new(file.path).to_hex.first
end
end
I think the reason miro produces better results is it handles the alpha channel of PNGs internally but colorscore doesn't.
My change above does renders this plugin useless for me 😅
Instead of doing what the readme recommends:
I had to do this:
With the following background worker:
This is after updating to the latest shrine version. The reason is
io.path
is not defined forUploadedFile
objects. We have to ultimately download the full file to get a color from it. And best to do it in a background job.I'm not sure but this could be a case unique to people doing direct to S3 uploads 🤷♂
The text was updated successfully, but these errors were encountered: