Help with Ignoring styles in paperclip processors ?!?

383 views
Skip to first unread message

matt

unread,
Jan 5, 2010, 4:39:20 AM1/5/10
to Paperclip Plugin
Hi all,

Me here again - I came to revisit this issue last night - but alas
(after 2 hours of frustration and trying different combinations
of :proccessors in styles, custom before_post_process methods and
patching the thumbnail processor) I couldn't achieve what I was after.

With the code definition below; the [ :file_content_processor ] will
still always get called 3 times on the asset, once with the original
and again with the 2 defined styles.

So my question again, is there anyway to have this adjusted so that
the :file_content_processor only gets called once, for the original
file and skips the other styles??

Or perhaps there is a way for me to have a processor nil out the other
styles if its not the original style (using options in the styles
hash) - but it seems the processor must always return a file.

If it comes to it, I don't mind patching paperclip to achieve this in
my app - but where would I start with that?

m


Original post follows from;
http://groups.google.com/group/paperclip-plugin/browse_thread/thread/b6ec26fc961ae7d7/dd4d615c6cdb902d?q=

Hi,
I have written a small processor, that basically looks at the
filetype
and if it is deemed to be 'editable' (ie. plain txt or html) - it
save
the contents of the upload file into a text attribute on the rails
model (asset_contents)
The problem I have is that I have multiple styles on the attachment
like so;;
<pre>
has_attached_file :asset, :styles => { :thumb =>
["64x64#", :jpg], :preview => ["200x", :jpg] },
:path => ":rails_root/public/images/u/
assets/:class/:id/:style_:basename.:extension",
:url => "/images/u/
assets/:class/:id/:style_:basename.:extension",
:default_url => "/images/missing_:class.gif",
:processors => lambda { |u| u.editable? ?
[ :file_content_processor ] : [ :thumbnail ] }
</pre>
In this case, my file_content_processor is fired for each of the
styles, effectively doing the operation twice (when I only want it
done once)
This also give me three files, the original (txt file), and a thumb
and preview (both jpg's with plain text content)
In the paperclip docs its states;
"" then both the :rotator processor and the :ocr processor would
receive the options "{ :quality => :better }". This parameter may not
mean anything to one or more or the processors, and they are free to
ignore it. ""
My question is, how do I ignore the multiple styles and have my
file_content_processor, just fire once ?
Ps.. my file content processor code is here;
http://pastie.org/425598
Regards,
Matt

matt

unread,
Jan 5, 2010, 4:49:22 AM1/5/10
to Paperclip Plugin
It appears this post may help me;

[paperclip] Can you intelligently apply styles to Paperclip
uploads?
http://groups.google.com/group/paperclip-plugin/t/1ae2c557df131919

I'll try that

m

On Jan 5, 9:39 am, matt <m...@hiddenloop.com> wrote:
> Hi all,
>
> Me here again - I came to revisit this issue last night - but alas
> (after 2 hours of frustration and trying different combinations
> of :proccessors in styles, custom before_post_process methods and
> patching the thumbnail processor) I couldn't achieve what I was after.
>
> With the code definition below; the [ :file_content_processor ] will
> still always get called 3 times on the asset, once with the original
> and again with the 2 defined styles.
>
> So my question again, is there anyway to have this adjusted so that
> the  :file_content_processor only gets called once, for the original
> file and skips the other styles??
>
> Or perhaps there is a way for me to have a processor nil out the other
> styles if its not the original style (using options in the styles
> hash) - but it seems the processor must always return a file.
>
> If it comes to it, I don't mind patching paperclip to achieve this in
> my app - but where would I start with that?
>
> m
>

> Original post follows from;http://groups.google.com/group/paperclip-plugin/browse_thread/thread/...

Reply all
Reply to author
Forward
0 new messages