I noticed that solidus active_storage png variants...
# support
u
I noticed that solidus active_storage png variants are left with sRGB colors and large file sizes. Setting colors 256 in imagemagick cuts the file size to 1/4. Anyone optimized this? Also i'm not sure how to regenerate my previously created variants after changing variant logic.. Any tips appreciated
c
Hey @1Maskhal, great observation, maybe worth creating an issue with your findings! It looks like active storage generates the variants on demand, but if you delete a variant from the folder it should reprocess it. I haven't had to do that myself so you probably want to do some testing around this. Justin Searls has a blog post on wrapping attachments in a model and which has a method to re-process the files you can check out here - https://justin.searls.co/posts/drive-by-active-storage-advice/ but I haven't personally tried this out either.
u
Thanks for the pointers I'll share some findings here for now. Removing variants Running
ActiveStorage::VariantRecord.destroy_all
does work by creating sidekiq jobs for each record that also removes related files and records etc. I tried to find a more efficient way but nothing seemed to work. This way also seems very safe for production so i guess it can be worth the wait.. Once you remove everything locally once, it is easy to remove again after a single page load as only a few records are created per page. Then
Rails.cache.clear
and hard refresh helped remove some NS binding aborted network errors. Optimizing variants UPDATE: I decided to use webp instead - snippet at bottom (previous png optimizaion code below) This reduces png size to less than 1/4 and jpg just slightly (i guess default jpg q = 80). I'm not sure 256 colors and 65% quality is really enough here though. Not sure what makes sense 😛
❤️ 1
Untitled.rb
I ended up just changing to webp
c
Thanks for sharing your findings here, this will be helpful to reference in the future
❤️ 1