In a Trailblazer operation that uses Paperdragon to process an image, code like this is typical:
def process(params)
validate(params) do |f|
f.image!(f.upload) do |v|
v.process!(:original)
v.process!(:version_a) { |job| job.something... }
v.process!(:version_b) { |job| job.something... }
v.process!(:version_c) { |job| job.something... }
end
end
end
end
which would create four versions from an uploaded image that is accessible as upload
on the operation's contract.
I would like to do a few things to :original
resulting in :edited
and then use :edited
as the baseline for :verson_a
, :version_b
and :version_c
. How can I achieve that with Paperdragon?
You can run a second processing block using a version created by the first as its input:
def process(params)
validate(params) do |f|
f.image!(f.upload) do |v|
v.process!(:original)
v.process!(:edited) { |job| job.thumb!(crop) }
end
end
f.image!(f.file(:edited)) do |v|
v.process!(:version_a) { |job| job.something... }
v.process!(:version_b) { |job| job.something... }
v.process!(:version_c) { |job| job.something... }
end
f.save
end
end
where file
is a method on the contract:
def file(version)
File.new(Dragonfly.app.datastore.server_root+image[version.to_sym].url)
end