Comments (7)
not really - it takes as long as imagemagick takes to resize the image (with "convert"), then analyse it with "identify". where are you doing it?
from dragonfly.
I've got similar issues where I have a page that contains a large number of variable-height images whose dimensions need to be in the HTML for clientside layout javascript to work. The are all resized to a known width though, so I can use the aspect ratio of the original image (fast to get as it's just a call to identify
) to calculate the height in my code.
If both dimensions of the resized image are known as for the OP, we could even skip the call to identify entirely.
It would be nice if this kind of optimisation could be pushed down into dragonfly so that for simple geometry strings where at least one dimension is known (which I imagine to be the vast majority of cases) it can transparently give a faster answer.
from dragonfly.
i think best way is add image caching(save to some folder all converted images with metadata). and add ability to rebuild (or clear) this cache.
from dragonfly.
gerrit - I think the best thing is to add a column on your model
"<attachment_name>_aspect_ratio"
- because it's a 'magic attribute' this will be automatically populated when you first upload the image (see http://markevans.github.com/dragonfly/file.Models.html#_Magic__Attributes )
You shouldn't be doing any calls to identify when rendering the html page I think.
Given that you know the width, you can just get the height of the thumbnails from (width/aspect_ratio).round
Unless you can think of a simple way of doing it, I don't think it should be up to dragonfly to do this because it would greatly complicate the analyser, which by design is supposed to be very simple.
from dragonfly.
Have a look at some code where I'm doing this: https://github.com/gerrit/radiant-assets-extension/blob/f6136d7716b9e5dabee4b10376fcc200866fd427/app/models/asset_tags.rb#L177-189
So, pretty much as you're describing it.
If you don't want to change the analyser interface (understandable as it's a documented extension point), the optimisation could take place in Job::OverrideInstanceMethods where we could simply define width/height methods.
from dragonfly.
yeh that could be a place, though width and height are specific to the imagemagick configuration and shouldn't be hard-coded onto there, so we'd have to find a way to add it as part of the configuration.
if it's ok I'm not going to work on this because adding the xxx_aspect_ratio column should work ok and I don't want to add to much magic/complexity.
Feel free to fork it and add it yourself though and if you can find a clean way of doing it we can add it to core. I'm going to close this issue if that's ok - thanks for the suggestions!
from dragonfly.
Just wanted to share a fairly straightfoward solution for those Googling.
Rather than trying to parse the geometry string yourself and calculating dimensions based on aspect ratios (messy), you can lean on Dragonfly's convenient methods and cache the result. Thus there'll only ever be a single request to the slow method. You could even call the method beforehand (ieafter_create
) to avoid any slow request on the user's dime.
Here's what I arrived at (in Rails, I'm sure you can adapt this).
Memoize dragonfly image dimensions
https://gist.github.com/3375756
class User < ActiveRecord::Base
image_accessor :avatar
serialize :avatar_geometries, Hash
def avatar_dimensions(geometry)
unless avatar_geometries.has_key?(geometry)
geometries[geometry] = {
thumb = avatar.thumb(geometry)
width: thumb.width,
height: thumb.height
}
save
end
OpenStruct.new(geometries[geometry])
end
end
An OpenStruct is returned for convenience, ie user.avatar_dimensions('200x300').width
from dragonfly.
Related Issues (20)
- Can't store resized pdf as jpg HOT 5
- Requesting filename without download file for custom stores HOT 2
- Turning Off Logs HOT 1
- Dragonfly unit test cases failing in Rails 4 HOT 1
- Dragonfly::FileDataStore::UnableToFormUrl: you need to configure server_root for Dragonfly::FileDataStore in order to form urls
- How to ignore "Dragonfly::FileDataStore destroy error"?
- Adding the ability to specify headers for a URL based attachment HOT 3
- Fetching url in the background
- after_assign's copy_to doesn't fire when using retained_image HOT 1
- SSL verification mode option
- warning: loading in progress, circular require considered harmful HOT 1
- is this version of Dragonfly compatible ? HOT 4
- Support for posix-spawn? HOT 2
- Security Issue Report HOT 1
- Guidance on upgrading to 1.4.0 HOT 7
- validate problems?
- CSS style color raising InvalidParameter when using plain generator HOT 1
- Questions about GHSA-qrgf-jqqm-x7xv HOT 2
- Allowing quality and interlace params for imagemagick thumb processor
- Unable to get dragonfly server to work with CORS
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dragonfly.