Image styles theme function theme_image_style() uses $variables['getsize'] = TRUE to determine width/height
But this feature was removed from theme_image() in favour of explicitly passing in $variables['width'] and $variables['height']
This causes problems such as #1012324: Images don't display fully when visiting the view's URL
The following adds this functionality back:
function theme_image_style($variables) {
$style_name = $variables['style_name'];
$path = $variables['path'];
// theme_image() can only honor the $getsize parameter with local file paths.
// The derivative image is not created until it has been requested so the file
// may not yet exist, in this case we just fallback to the URL.
$style_path = image_style_path($style_name, $path);
if (!file_exists($style_path)) {
$style_path = image_style_url($style_name, $path);
}
$variables['path'] = $style_path;
if ($variables['getsize'] && (is_file($style_path) && (list($width, $height, $type, $attributes) = @getimagesize($style_path)))) {
$variables['width'] = $width;
$variables['height'] = $height;
}
return theme('image', $variables);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 1012416-getsize-4.patch | 1.85 KB | redndahead |
| #5 | 1012416-getsize-3.patch | 1.85 KB | redndahead |
| #3 | 1012416-getsize-2.patch | 1.62 KB | redndahead |
| #1 | 1012416-getsize-1.patch | 851 bytes | redndahead |
Comments
Comment #1
redndahead commentedHere is the patch
Comment #3
redndahead commentedTest weren't passing because during render getsize was set to false when the default value is true. So output wasn't matching. Fixed the test.
Comment #5
redndahead commentedLet's try this one. Need to use theme('image_style' since that is what is being used to display the image on the node. This also takes different variables.
Comment #6
redndahead commentedThis patch just removes extra white spacing. Will still pass tests.
Comment #7
redndahead commentedIf you want to see a place where the change is made you can add an image to a user profile. Before the patch the image will not have the width and height attributes on them. After the patch they will be there. This should also be the case with an image field.
You can also see where this existed in imagefield module before being incorporated into d7. On line 328:
http://drupalcode.org/viewvc/drupal/contributions/modules/imagefield/ima...
Comment #8
threewestwinds commentedWorks great for me, and code looks good. The change to the test has no functional change - it just uses the API properly instead of unnecessarily doing a manual step. Let's make stuff work like it's supposed to.
Comment #9
webchickOk, I knew I recognized this issue.
See #908282: Remove unnecessary I/O from theme_image() where this was removed, on purpose. :( :( We'll need to get some reviews from the folks over there in order to add this back, though I agree it's a major WTF right now that we have a function argument that completely lies.
Comment #10
sunReasoning for why getsize doesn't work for image styles:
#908282-15: Remove unnecessary I/O from theme_image()
Comment #11
eric_a commentedIn the other issue I just suggested that we need a new render element type.
I feel that code like this really should be in a preprocessor or in a render element type. The point being that theme functions and templates are for markup and overriding markup, basically.
Comment #12
luco commentedthe patch provided by redndahead in #6 worked for me. thanks :]
Comment #13
redndahead commented@luco I wouldn't use that patch. In a future release of drupal 7 it won't work anymore.
Comment #14
Wolfgang Reszel commentedYou could add the function to your template.php. For Drupal 7.2 you have to remove "$variables['getsize'] && " from the if statement.
Comment #15
slackrunner commented#6: 1012416-getsize-4.patch queued for re-testing.
Comment #17
redndahead commentedPlease do not run tests on this. It's not going to get fixed.
Comment #18
eric_a commentedIt is being fixed in #1129642: Populate HTML image tags with dimension attributes (like D6 imagefield) without re-introducing I/O in a better way.
Comment #19
sumerokr commented#6: 1012416-getsize-4.patch queued for re-testing.
Comment #21
damien tournoud commentedComment #22
jpmesquita commented#6: 1012416-getsize-4.patch queued for re-testing.
Comment #24
redndahead commented