Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've been working with Insert + Highslide modules and noticed that width and height attributes of imagecache thumbnail are not set until image is generated by imagecache.
I fixed this by customizing theme_imagecache function by replacing these lines:
if ($getsize && ($image = image_get_info(imagecache_create_path($presetname, $path)))) {
$attributes['width'] = $image['width'];
$attributes['height'] = $image['height'];
}
With my new ones:
if ($getsize) {
$cachepath = imagecache_create_path($presetname, $path);
if (!is_file($cachepath)) {
$preset = imagecache_preset_by_name($presetname);
$dst = imagecache_create_path($presetname, $path);
imagecache_build_derivative($preset['actions'], $path, $dst);
}
if ($image = image_get_info($cachepath)) {
$attributes['width'] = $image['width'];
$attributes['height'] = $image['height'];
}
}
This code generates the image if it's not generated already.
Comment | File | Size | Author |
---|---|---|---|
#8 | dimensions_missing-1047416-8.patch | 968 bytes | fuzzy76 |
Comments
Comment #1
Brodingo CreditAttribution: Brodingo commentedI tried to override theme_imagecache as phptemplate_imagecache with this code and neither width or height was set when I inserted an image.
Comment #2
jrstmartin CreditAttribution: jrstmartin commentedThank you for this! I was having a problem in Views Slideshow where the first/new slide, which contained an image, was halfway hidden. The height that Views Slideshow's JS was setting on the enclosing
<div>
was wrong because it couldn't calculate the dimensions of the image contained within it, as the dimensions were not set. This patch sets the dimensions and everything is working!Comment #3
fizk CreditAttribution: fizk commentedMarking as ImageCache 3.x Todo.
Comment #4
j0rd CreditAttribution: j0rd commentedSame problem and causes a fairly large bug on my website, since I depend on these values being there for some image resizing JS I'm doing. Just noticed this problem after I changed the imagecache's and flushed the images and now my website doesn't work as expected.
Comment #5
borgewarvik CreditAttribution: borgewarvik commentedI can confirm that this patch is working. Any plans on implementing it in an release soon?
Comment #6
fizk CreditAttribution: fizk commentedComment #7
fuzzy76 CreditAttribution: fuzzy76 commentedWorks for me.
Comment #8
fuzzy76 CreditAttribution: fuzzy76 commentedRerolled against 2.0-rc1.