Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Feature request: persist image dimensions #1129

Closed
johnnyshields opened this issue Jan 9, 2013 · 15 comments
Closed

Feature request: persist image dimensions #1129

johnnyshields opened this issue Jan 9, 2013 · 15 comments

Comments

@johnnyshields
Copy link
Contributor

I imagine this topic has been raised before but...

I'd like to request to that paperclip provide a simple facility to persist image dimensions (width x height) and file size, something like the following API:

@model.avatar(:large).width      #=>  125
@model.avatar(:large).height     #=>  100
@model.avatar(:large).dimensions #=>  [125, 100]
@model.avatar(:large).file_size  #=> 39231 (bytes)

I think it's silly that I'm required to schlep around with 3rd party gems (paperclip-meta and paperclip-dimension) for what should be an out-of-the-box feature.

I would be glad to implement it if there's a willingness to include this feature.

@guyisra
Copy link

guyisra commented Jan 9, 2013

+1

@maclover7
Copy link
Contributor

Hi @johnnyshields ! I know this issue is a bit old (from almost 2 years ago). If this is still something you want, would you be willing to send in a PR?

@johnnyshields
Copy link
Contributor Author

@maclover7 this is a feature request and yes it is something we should keep open. I do not have a PR currently.

@tute
Copy link
Contributor

tute commented May 29, 2015

Paraphrasing @jyurek:

if someone says, say, “I want to store image dimensions in paperclip”, [...] I’m not going to do that feature, because I don’t believe it’s in the goal of Paperclip to handle that.

Closing, as he doesn't want paperclip to handle this. I would appreciate a longer description on why he thinks that way.

@tute tute closed this as completed May 29, 2015
@johnnyshields
Copy link
Contributor Author

@tute I think we should leave this issue open until we get a better explanation.

I'm actually curious how people can live without storing the image dimensions--how do you know what size image you're going to display in advance, especially if variable dimension Rmagick settings are being used?

@tute
Copy link
Contributor

tute commented May 29, 2015

I think the same! And the lack of people complaining about this seemingly for us important lack makes me think we might be missing something, or it's actually not a common use case.

I'd leave it open, but we are overwhelmed with issues and PRs for now, and there's higher priority bug reports in it. I also want to hear more of @jyurek's thoughts, but knowing he doesn't consider this an issue in the library, I'm ok with leaving it closed for now, signaling it doesn't await a fix. Discussion should continue though.

@johnnyshields, in the past month we've been working heavily on the issues, finding duplicates, doing code reviews, etc. We didn't find time yet to write new code though. If you'd rather have this feature in, don't hesitate to help on this work, continuing discussion of this one, and probably discussing over code, too! Specially if the addition would be small.

Thanks!

@johnnyshields
Copy link
Contributor Author

Well, it's a bit of a human deadlock here as I'm unlikely to spend time on a well-crafted PR if @jyurek is going to deny it on the basis of "don't want this feature." @jyurek please help us by chiming in.

@jyurek
Copy link

jyurek commented May 29, 2015

It's not something I'm immediately opposed to, but I would wonder how it's going to be implemented. The sample in the OP was that we could do @model.avatar(:large).dimensions, which implies that we store all the dimensions for all the styles. This would lead to a bunch of columns potentially.

However, Paperclip does already have the ability to store data in columns that may or may not exist, so this might not be as bad as I fear.

Let's go with 👍, and we can discuss the specifics of the PR when it hits. Thanks, @johnnyshields

@johnnyshields
Copy link
Contributor Author

@jyurek thanks! Will add this to our team's development queue.

I use Mongoid and I store image dimensions as a Hash (which Mongoid supports natively) something like:

avatar_dimensions = { large: [200, 188], medium: [100, 94] }

Then model.avatar(:large).dimensions would return [200,188]. My memory is hazy here I'm not sure that's what it actually does currently, but at a bare minimum you can do model.avatar_dimensions[:large]

For ActiveRecord we could store the same as a JSON string which is read in using JSON.parse. Thoughts?

@jyurek
Copy link

jyurek commented May 29, 2015

Well, I'd want to let ActiveRecord handle the serialization rather than do JSON parsing ourselves, but I suppose that could work. I don't know if the serialization "just works" with Postgres' JSON or hstore columns, but that would be super nice.

@sleung-ttc
Copy link
Contributor

+1 to this feature. I had to create seperate columns to cache dimension as retrieving it is a rather slow operation. It would be nice the caching isbuilt in.

@tute tute reopened this May 29, 2015
@tute
Copy link
Contributor

tute commented May 29, 2015

I don't know if the serialization "just works" with Postgres' JSON or hstore columns, but that would be super nice.

It does "just work".

@johnnyshields
Copy link
Contributor Author

Great, I think serialization is the right choice as the data is variable-length (depends on model definition of sizes) and I don't think there is any practical requirement to deep-query for specific sizes.

@jyurek
Copy link

jyurek commented May 29, 2015

That's why I was hoping that the JSON/hstore columns "just work" because you can deep query if needed. So that's awesome.

@mike-burns
Copy link
Contributor

Thank you for the feature request. Unfortunately we will be deprecating Paperclip and therefore will no longer be accepting new features.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants