This repository was archived by the owner on Oct 5, 2018. It is now read-only.
This repository was archived by the owner on Oct 5, 2018. It is now read-only.
Processors not being called #211
Open
Description
Hello guys,
The basic features works like a charm but I have 2 processors to crop 2 images, and those processors are not being called. Since I don't use reprocess!
due to loop issues with the latest Paperclip, the other approach to it seems to not trigger the processors.
Heres some code to illustrate:
class Party
...
# Filters
after_update :reprocess_mobile_cover, if: :cropping_mobile_cover?
after_update :reprocess_cover, if: :cropping_cover?
...
# Cover
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h, :ratio
has_mongoid_attached_file :cover,
styles: {normal: ["1200x630#"]},
processors: [:cropper]
process_in_background :cover, queue: 'images.cover'
attr_accessor :mobile_crop_x, :mobile_crop_y, :mobile_crop_w, :mobile_crop_h, :mobile_ratio
has_mongoid_attached_file :mobile_cover,
styles: {normal: ["730X1344#"]},
processors: [:mobile_cropper]
process_in_background :mobile_cover, queue: 'images.mobile_cover'
def cropping_mobile_cover?
!mobile_crop_x.blank? && !mobile_crop_y.blank? && !mobile_crop_w.blank? && !mobile_crop_h.blank?
end
def cropping_cover?
!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end
def mobile_cover_geometry(style = :original)
@geometry ||= {}
mobile_cover_path = (mobile_cover.options[:storage] == :azure ? mobile_cover.url(style) : mobile_cover.path(style))
@geometry[style] ||= Paperclip::Geometry.from_file(mobile_cover_path.gsub('https', 'http'))
end
def cover_geometry(style = :original)
@geometry ||= {}
cover_path = (cover.options[:storage] == :azure ? cover.url(style) : cover.path(style))
@geometry[style] ||= Paperclip::Geometry.from_file(cover_path.gsub('https', 'http'))
end
def reprocess_mobile_cover
mobile_cover.assign(mobile_cover)
mobile_cover.save
end
def reprocess_cover
cover.assign(cover)
cover.save
end
And here it's the processor code (the other one is pretty similar):
module Paperclip
class Cropper < Thumbnail
def transformation_command
if crop_command
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
else
super
end
end
def crop_command
target = @attachment.instance
if target.cropping_cover?
[" -crop #{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}"]
end
end
end
end
Am I missing something to get those processors called? If yes, what?
Thanks a lot :)
Metadata
Metadata
Assignees
Labels
No labels
Activity