How run a process only on the main version?

109 views
Skip to first unread message

mix

unread,
Apr 6, 2011, 1:13:36 PM4/6/11
to carrierwave
Hi, I migrated to 0.5.x and I've a problem, previously I did this:

process :resize_to_fit => [800, 600]
process :optimize_image
process :watermark => Rails.root.join("public", "images",
"watermark.png")

version :thumb do
process :resize_to_fit => [80, 80]
process :optimize_image
end

And it worked, only the main version had the watermark, now with the
0.5 version it's added to the thumb too!

I tried to do version nil, version :nil, version "", but it doesn't
work... with :nil it create a new version and it keep the original
one, but it just want 2 version: the main one and the thumb

Any hint?

Thanks

mix

unread,
Apr 14, 2011, 2:41:03 PM4/14/11
to carri...@googlegroups.com
anyone about this? ;)

Nick Mulder

unread,
Apr 14, 2011, 3:08:50 PM4/14/11
to carrierwave
I have a similar problem outlined this post:
http://groups.google.com/group/carrierwave/browse_thread/thread/c83d4ab2b35f08ae?hl=en

I needed a version which keeps the original size from the upload.

I've forked carrierwave and this is a commit that implements what I
needed. https://github.com/mulder/carrierwave/commit/d098295c0f326a124506ab06b8fc944acdf9dddf

I hate the name I gave it but here is how its used:

class IPhoneImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick

storage :file

process :resize => ['50%']

version :retina do
use_pre_processed_file!
end

# Pipes size_string param into an mini_magick resize call.
def resize(size_string)
manipulate! do |img|
img.resize size_string
img = yield(img) if block_given?
img
end
end
end


The use_pre_processed_file! is the method you want. After my commit
using this will make the version use the originally uploaded image to
apply its processing to, instead of building off main version.

I think this is a pretty useful feature. If some one can come up with
a better name i'll move things into a feature branch and wrap things
up with some specs then init a pull request.

Also if someone has a better implementation behind the scenes please
chime in.

On Apr 14, 2:41 pm, mix <fausto.ga...@email.it> wrote:
> anyone about this? ;)

Jonas Nicklas

unread,
Apr 15, 2011, 5:45:13 AM4/15/11
to carri...@googlegroups.com, Nick Mulder
That sounds like a useful feature, maybe something like:

version :thumb, :use_original_image => true do

end

/Jonas

> --
> You received this message because you are subscribed to the Google Groups "carrierwave" group.
> To post to this group, send email to carri...@googlegroups.com.
> To unsubscribe from this group, send email to carrierwave...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/carrierwave?hl=en.
>
>

Nick Mulder

unread,
Apr 15, 2011, 8:15:19 AM4/15/11
to carrierwave
That was my first through, but after looking at the code the version
method didn't seem to be working with an options hash. I didn't want
to open up that flood gate, so I just stuck with the ! method
approach. I'll all for the options hash method and we wouldn't need
the empty block either.

Jonas if you think the options hash is best I'll get that going.
Though we could probably support both if we wanted....

Nick

On Apr 15, 5:45 am, Jonas Nicklas <jonas.nick...@gmail.com> wrote:
> That sounds like a useful feature, maybe something like:
>
> version :thumb, :use_original_image => true do
>
> end
>
> /Jonas
>
>
>
>
>
>
>
> On Thu, Apr 14, 2011 at 9:08 PM, Nick Mulder <nicholas.mul...@gmail.com> wrote:
> > I have a similar problem outlined this post:
> >http://groups.google.com/group/carrierwave/browse_thread/thread/c83d4...
>
> > I needed a version which keeps the original size from the upload.
>
> > I've forked carrierwave and this is a commit that implements what I
> > needed.  https://github.com/mulder/carrierwave/commit/d098295c0f326a124506ab06...

Nick Mulder

unread,
Apr 26, 2011, 9:56:51 AM4/26/11
to carrierwave
I have submitted a pull request that supports this option and even has
some specs for it.

I'm hoping to makes it in as we are using it and its working well for
us.

Nick

On Apr 15, 5:45 am, Jonas Nicklas <jonas.nick...@gmail.com> wrote:
> That sounds like a useful feature, maybe something like:
>
> version :thumb, :use_original_image => true do
>
> end
>
> /Jonas
>
>
>
>
>
>
>
> On Thu, Apr 14, 2011 at 9:08 PM,NickMulder <nicholas.mul...@gmail.com> wrote:
> > I have a similar problem outlined this post:
> >http://groups.google.com/group/carrierwave/browse_thread/thread/c83d4...
>
> > I needed a version which keeps the original size from the upload.
>
> > I've forked carrierwave and this is a commit that implements what I
> > needed.  https://github.com/mulder/carrierwave/commit/d098295c0f326a124506ab06...
Reply all
Reply to author
Forward
0 new messages