Hi guys, has anyone faced the issue where product ...
# support
z
Hi guys, has anyone faced the issue where product image quality is very poor once its uploaded to admin? Unsure how I can go about addressing this, it happens both in dev and prod
1
j
I believe the most current solidus is still using paperclip? -- in either case, when you go to render the image do you see something like
:small
in the function signature? -- you should be able to specify
:original
to get the original file you uploaded. The images get automatically post processed and minified to make them look good for say a thumbnail, but if you use the thumbnail to render a large image, it will look very poor. I tend to just pre process myself and use
:original
in the code
j
ActiveStorage is the default now.
z
yes I believe it is Active storage being used, is there something similar that can be done with the image component code?
Copy code
# frozen_string_literal: true

class ImageComponent < ViewComponent::Base
  attr_reader :image, :size, :classes, :options

  def initialize(local_assigns = {})
    @image = local_assigns.delete(:image)
    @size = local_assigns.delete(:size) { :mini }
    @classes = local_assigns.delete(:classes)
    @options = local_assigns
  end

  def call
    if image
      image_tag image.url(size), default_options.merge(options)
    else
      content_tag :div, nil, class: ['image-placeholder', size].join(' ')
    end
  end

  private

  def default_options
    { alt: image.alt, class: classes }
  end
end
c
@Zyad A You would want to confirm in your views what’s being passed as the
size
to that
ImageComponent
and adjust according to your needs. Based on this partial it looks like it’s using the
:product
size https://github.com/solidusio/solidus_starter_frontend/blob/15e338897e83d10722521ba[…]e693f51b36/templates/app/views/products/_product_image.html.erb that is defined through configuration and you can change that in your app https://github.com/solidusio/solidus/blob/6a732e2711d834656ed1d9072abf0a8130f0c265/core/lib/spree/app_configuration.rb#L541-L544
I am not sure if active storage processes on the fly but with paperclip I think you need to re-process all the images if you change the styles configuration.
The legacy guides actually explain this and it looks like we may have lost that update in the move to the new guides (i’ll create a bug ticket) https://legacy-guides.solidus.io/developers/products-and-variants/product-images#image-settings
Based on that it sounds like Active Storage will generate the new sizes from the original on initial request, so you just have to make sure the assets you are uploading are high enough resolution.
z
Thanks for the help Chris. That is strange though because the images are very high quality, however as soon as they are passed into the admin page they seem to lose the quality. Still digging in to this but do let me know if you have any other thoughts on potential causes for this issue.
c
What resolution are the images showing up on your PDP as?
The admin won’t be displaying the original quality image so you shouldn’t judge by that
z
I believe I've isolated the issue: when an image is uploaded to admin an s3 object is correctly created with the correct file size and resolution using:
Copy code
Processing by Spree::Admin::ImagesController#create as JS

Parameters: {"image"=>{"attachment"=>#<ActionDispatch::Http::UploadedFile:0x00007f2f14770868 @tempfile=#<Tempfile:/tmp/RackMultipart20230215-2-yglpp0.jpeg>, @original_filename="a1.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"image[attachment]\"; filename=\"a1.jpeg\"\r\nContent-Type: image/jpeg\r\n">, "viewable_id"=>"49"}, "upload_id"=>"c8", "product_id"=>"test"}
the issue is that after that, several more versions are created at different sizes and resolutions there is repeated log of (same key)
Copy code
[ActiveStorage::AnalyzeJob] [3e884de1-f1ea-4fd1-9e46-e55ee326cd00] [Aws::S3::Client 200 0.085494 0 retries] head_object(bucket:"permanence-bucket",key:"dbgbxqtkvw70p773u2kgnedr4u6q")
followed ultimately by new object creation
Copy code
[Aws::S3::Client 200 0.163308 0 retries] put_object(body:#<Tempfile:/tmp/image_processing20230215-2-iy3bu0.jpeg>,content_md5:"9L+s+mwcBVMlPUxdDZngXw==",content_type:"image/jpeg",content_disposition:nil,metadata:{},bucket:"permanence-bucket",key:"o8yv5zkmwzj99tz014noepb9ij6f")
Working to figure out why this is happening, any suggestions would be awesome!
wow... after days of headbanging I realised that the different images uploaded are the four sizes of images created by the controller and that i was using the :small size instead of the :product size.... not sure whether to laugh or cry hahahaha but so relieved hahah
c
Glad you were able to figure it out after all!
z
thanks for your responses and suggestions, very helpful
❤️ 1
can I be cheeky and ask one final question? All is working as required but one issue that has persisted is that every little while the images will return 403 errors and not render. I have found nothing on the internet or in any of the logs about this issue, I have made my bucket and objects public so it seems it isn't permissions. Is there anything else I can look in to?
c
Haha, this actually comes up as a question pretty often!
@Jared Norman may have a resource to point you to, but you should make sure you are not using expiring URLs
That seems to be the most common culprit. Expiring URLs combined w/ view caching are a known source of problems
z
ahh interesting thanks for that! Added the code below, hopefully that helps.
Copy code
config.active_storage.service_urls_expire_in = false
c
It looks like this was fixed at some point in Active Storage (https://github.com/rails/rails/commit/94584c2510743a45d9030d1b94dd33a074518b17#diff-9b9d88e810eebaae9a2b7c2af029e004aec87617a65fcd18890b7279e806cb19) The related documentation change seems to indicate you can configure it in
config/storage.yml
per service. This is the related issue https://github.com/rails/rails/pull/36729
I don’t have any Active Storage experience so someone else may be able to point you to the best solution.
z
okay thank you for the info, I will share the question with the wider group to see if someone with AS experience can help
👍🏼 1
c
Yeah probably best to start a new thread for more visibility 👍🏼
🙏 1