I found a way to generate custom Open Graph images for Sample files on this site using an SVG partial that is rendered and converted to PNG by ImageProcessing::Vips.
class SampleFile < ApplicationRecord has_one_attached :open_graph_image def update_open_graph_image self.open_graph_image.attach(io: CreateSampleFileImage.new(self).create, filename: "sample_file_#{id}.png") end end
The #update_open_graph_image is called from a background job to create and attach the OG image.
#update_open_graph_image