Image dimensions

63 views
Skip to first unread message

greg

unread,
Jun 1, 2012, 5:20:47 PM6/1/12
to carrierwave
I'm trying to store image dimensions with the following...and while
I'm not getting errors, the dimensions aren't being stored.

What should I be putting in my controller to make sure the dimensions
are stored? Or how would be best to get if img is actually showing
any dimensions? I don't see them passing in the terminal. Thank you!

class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
# ...
process :store_geometry
def store_geometry
if @file
img = ::Magick::Image::read(@file.file).first
if @post
@post.width = img.columns
@post.height = img.rows
end
end
end
# ...
end

Daniel Doubrovkine

unread,
Jun 2, 2012, 4:22:25 PM6/2/12
to carri...@googlegroups.com
The uploader belongs to a post? Then you should do model.width, etc.


--
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.




--

dB. | Moscow - Geneva - Seattle - New York
dblock.org - @dblockdotorg


greg

unread,
Jun 3, 2012, 3:00:11 PM6/3/12
to carrierwave
Post is the name of my model. I've tried leaving as just model or
using Post, but no data is being passed through.

Is there anything I should be putting into my controller?

process :store_geometry
def store_geometry
if @file
img = ::Magick::Image::read(@file.file).first
if model
model.width = img.columns
model.height = img.rows
end
end
end

On Jun 2, 4:22 pm, Daniel Doubrovkine <dbl...@dblock.org> wrote:
> The uploader belongs to a post? Then you should do *model.width*, etc.
> dblock.org <http://www.dblock.org> -
> @dblockdotorg<http://twitter.com/#!/dblockdotorg>

greg

unread,
Jun 3, 2012, 3:14:35 PM6/3/12
to carrierwave
This is what I'm seeing passed in parameters...no height or width
seeming to go through...

Parameters: {"utf8"=>"✓", "authenticity_token"=>"7Z7NuU/
rtJuD3AoocYXZ9MlJHwK93wFFvHHCfvfFY3Q=", "post"=>{"title"=>"blah",
"commentary"=>"blah", "avatar"=>#<ActionDispatch::Http::UploadedFile:
0x007fb7451648e8 @original_filename="IMG_0053.PNG",
@content_type="image/png", @headers="Content-Disposition: form-data;
name=\"post[avatar]\"; filename=\"IMG_0053.PNG\"\r\nContent-Type:
image/png\r\n", @tempfile=#<File:/var/folders/1s/
dh01tgyn3j39f673v1d_xywc0000gn/T/RackMultipart20120603-377-mnrfbn>>,
"remote_avatar_url"=>"", "avatar_cache"=>"", "width"=>"",
"height"=>"", "twitter"=>"", "frame"=>"/images/frame3.png"},
"commit"=>"Submit"}
Reply all
Reply to author
Forward
0 new messages