Closed (fixed)
Project:
Drupal.org security advisory coverage applications
Component:
module
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
6 Dec 2012 at 15:04 UTC
Updated:
8 Jan 2013 at 19:20 UTC
Provides a field formatter to display image fields using the foresight.js library. Core image effects are able to adjust scale dimensions to account for device pixel ratio and requested image size.
This means that:
Project page
http://drupal.org/sandbox/gigabates/1859182
Git
git clone http://git.drupal.org/sandbox/gigabates/1859182.git --branch 7.x-1.x foresight
Reviews of other projects:
Comments
Comment #1
gigabates commentedTagged for PAReview: review bonus
Comment #2
jhaskins commentedThere are several dynamic image resizing modules on drupal.org alread such as http://drupal.org/project/cs_adaptive_image (several more examples are linked from that page). Perhaps you should clarify on your project page & application how your module is different from those alternatives.
PAReview.sh turned up a bunch of issues; you may want to look at http://ventral.org/pareview/httpgitdrupalorgsandboxgigabates1859182git (most of it is whitespace/punctuation nitpicking but there are a few actual code issues. http://drupal.org/node/322731 should provide you with some insight on the install issues.
When "check bandwidth" is disabled, the url for my 2100x1400 image is output as sites/default/files/styles-foresight/1000x1000xundefined/huge/public/LHC.jpg. The "huge" image style is scale& crop 1000x1000 but that url returns the full size image. Checking the log reveals several warnings starting with
and culminating in an error:
which I'm guessing explains the image not being resized. If I try to access the "non-foresight" version of the "huge" image (sites/default/files/styles/huge/public/LHC.jpg) everything works fine.
When "check bandwidth" is on, it just outputs the url as sites/default/files/styles/huge/public/LHC.jpg with no errors in the log.
Comment #3
gigabates commentedI've added a comparison of alternative modules to README.txt. I'll update the project page with these too.
I've fixed all PAReview errors. Interesting that the coder module that I had been relying on didn't pick up any of these.
The errors caused by the 'undefined' scale value are due to a bug in the current version of foresight.js. I've created a fork of the project on Github with a fix, and linked to this version from the README.txt for now. I have raised an issue on the main project so hopefully this won't be needed for long. You can download the fork on https://github.com/grahambates/foresight.js/downloads.
Comment #4
dydave commentedHi gigabates,
Thanks very much for contributing this very nice module, adding more information to the README.txt file and fixing the coding standards errors.
I am wondering whether I have been testing your latest version of the module, which I think I did, since I checked out the head from your GIT, branch 7.x-1.x. This problem is so obvious that you might already have found it but perhaps just not committed.
1 - In file foresight.module, at line 69:
After installing the module, the permission is not displayed on the admin/people/permissions/list Permissions page, because of the function name.
I think you should simply change:
foresight_api_permission
to be foresight_permission (I've tested it and it works fine, as expected).
Maybe you simply changed your module name at a later stage of development and it's one of the find/replace that didn't go through.
2 - In file foresight.module, at line 112:
There's a t() call on the label property but not on description.
Perhaps you should consider adding a call to t() function, as you did in all other places in your module where you have a 'description' property.
I think that's the only place I found in your module where a call to t could be missing, but you could do another quick check I guess.
So far, that's all I could find and I hope it helps improving your very nice module.
Cheers!
Comment #5
dydave commentedForgot to change status.
Removing PAReview: review bonus tag: Reviews have been provided.
Hope these comments help.
Cheers!
Comment #6
gigabates commentedThanks for the feedback DYdave. I've implemented those changes.
Comment #7
gigabates commentedMore reviews:
http://drupal.org/node/1791048#comment-6829070
http://drupal.org/node/1837170#comment-6828946
http://drupal.org/node/1852590#comment-6820562
Comment #8
Jordan_Fei commentedHi gigabates,
Lines 378 and 379 in foresight.module:
$width_ratio = $request_width / $original_dimensions['width'];
$height_ratio = $request_height / $original_dimensions['height'];
There are division operations on above lines. Consider the exception of the denominator being zero.
Comment #9
gigabates commentedThanks for the feedback Jordan_Fei. Have you found a scenario where the dimensions of the original image could be zero?
This value is returned by image_get_info() and image_style_transform_dimensions() on an image file that we've confirmed exists. I thought it was a safe assumption that it contains real pixel dimensions.
Edit:
Actually I was wrong, I wasn't checking if the file exists (and was a valid image for that matter). I'm adding in an additional check for this. Is this how you got a divide by zero error - by putting an invalid image in the URL?
Comment #10
Jordan_Fei commentedYes, exception scenarios need to be considered as an robust module.
Comment #11
gigabates commentedYeah thanks Jordan_Fei. You're right of course, I was just wondering if you encountered the error in normal use. I've added a check for this now anyway so it should be all good.
Comment #12
klausiPlease add all your reviews to the issue summary.
manual review:
But that are no blockers, otherwise looks RTBC to me. Removing review bonus tag, you can add it again if you have done another 3 reviews of other projects.
Comment #13
gigabates commentedThanks for the review klausi.
I'm aware this would be preferable to inline JS, however the required execution order prevents this. The Foresight settings object need to be defined in the global scope before the Foresight library is included. The Drupal.settings object is not defined until the end of the header block and as far as I can see it's not possible to include any files after this, regardless of weight and grouping. The Foresight library need to be loaded in the header scope so that images are displayed as the page loads.
Agreed - changed it.
I actually took this block directly from image_style_deliver() in core. I'm not 100% sure why they take this approach but I'm guessing there's a good reason. Perhaps it's designed so the function is not limited to use as a menu callback? As this function is a direct equivalent of image_style_deliver() for this module I'm inclined to leave it this way.
Done.
Comment #14
dydave commentedRelated with #11.
Hi gigabates,
This caught my attention and I asked myself the same question as you did.
Actually, I was imagining that perhaps, if an image was corrupt, or missing from the server (but still recorded somewhere), or for any other reasons, maybe
image_get_info()would return 0 dimensions.....I'm not really sure either, so that's why I said maybe: it would need to be investigated further in code.
But I just wanted to also share my concern on this, after I saw your exchanges with Jordan_Fei.
I would be interested if anyone else encountered this type of issues before, and in which circumstances.
Thanks for all your comments and feedbacks.
Cheers!
Comment #15
gigabates commentedHi DYdave,
The implementations of
image_get_info()for both the GD and Imagemagick toolkits use the PHPgetimagesize()function to get the image dimensions. The manual page for this function states:I'm not sure whether this includes any formats allowed in an image field in Drupal, but it does seem sensible to add in an additional check. That said, I've seen plenty of other examples that don't.
Comment #16
dydave commentedThanks again for clarifying that and pulling the reference out from the PHP code.
So the suggested scenarios above, in #14 could correspond to this particular error case, couldn't they?
If I didn't misunderstand your answer, these could be among the potential error cases that would be likely to happen.
Thanks again for all your replies.
Cheers!
Comment #17
gigabates commentedSo to summarise, yes it is possible for
image_get_info()to return zero dimensions for the reasons stated. More likely though, if the image is missing or corrupt it would returnFALSE. This module now handles both scenarios.I'm not 100% clear if Jordan_Fei actually encountered an error case or was just talking about the theoretical possibility. Either way it would now be handled correctly.
Comment #18
dydave commentedHi gigabates,
Thanks for your prompt and precise answer.
That's what I had assumed.
I know for sure everything should be fine with Foresight Images, as far as this issue is concerned, but I was and still am curious to see if anyone could report encountering this type of errors on a real case scenario before.
Feel free to let me know if you hear anything from anyone about that, I would still be interested.
Thanks again for sharing this great module and nice work.
Cheers!
Comment #19
klausino other objections for more than a week, so ...
Thanks for your contribution, gigabates!
I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.
Comment #20.0
(not verified) commentedFormatting