Division by zero warning in image.inc, no images created.

janx - February 19, 2008 - 15:32
Project:Image
Version:6.x-1.x-dev
Component:image.module
Category:bug report
Priority:critical
Assigned:janx
Status:duplicate
Description

warning: Division by zero in /usr/home/xyz/domains/myDomain/public_html/sporta/includes/image.inc on line 160.
warning: Division by zero in /usr/home/xyz/domains/myDomain/public_html/sporta/includes/image.inc on line 160.
Unable to create scaled Thumbnail image
The removal of the original file has failed.

#1

yoroy - March 4, 2008 - 00:39
Title:Error by creating images» Division by zero warning in image.inc, no images created.
Priority:normal» critical

I get the same warning, except for the fourth, last line, mine says: "The selected file /bla/bla could not be copied."

- Images smaller than the thumbnail settings are no problem, they upload and display fine.
- anything above the max. thumbnail size gives the above warning, with one exception:

I set my thumbnail settings to scale and crop to 60x60px. I created square images of 59, 60, 61 and 62px.
- 59 & 60 px: all good
- 61px: some script seems to keep running, upload (or save?) never finishes. The browser stays responsive but never finishes loading
62px and more give the warning mentioned above. The new node is created, but without the image file.

This is on a local install under OS X,
Apache 1.3.33, PHP 5.1.6, Drupal6.1
from the Status Report:
File system Writable (public download method)
GD library bundled (2.0.28 compatible)
Image module directories Exists (sites/default/files/images)
Image toolkit The gd toolkit is installed

bump to critical for visibility (and general borkedness, for me at least :)

Thanks.

#2

yoroy - March 17, 2008 - 12:10

janx: assigning a issue to yourself means you will try and fix it. Are you or were you just reporting?

I still get the warning with latest build, march 04.

#3

bneijt - March 17, 2008 - 12:36

Hi readers,

Just wanted to mention that the given error occurs in Drupal (includes directory) and not the image module. It might even be a problem with gd not being installed as "@getimagesize" in images.inc:image_get_info() could just return false resulting in that the width and height of the image are not set.

If images.inc:image_scale_and_crop() would check the return value of image_get_info() it might all become allot clearer. Maybe this bug needs to be moved to the Drupal core??

#4

tic2000 - April 2, 2008 - 13:33

I had the same problem. Don't know what it's your case, but I had this problem when I set the "scale and crop image" option for one of the sizes.
The problem was in image.module on line 809:

<?php
$status
= image_scale_and_crop($destination, $destination$size['width'], $size['height']);
?>

I changed the above to:
<?php
$status
= image_scale_and_crop($original_path, $destination$size['width'], $size['height']);
?>

and all works fine now. The problem is that it passes twice the destination instead of the original path. The destination file doesn't exist yet, $info = image_get_info($source); returns NULL and $scale = max($width / $info['width'], $height / $info['height']); generates the error cause we have no $info['height'] or $info['width'].
Hope that helps.

#5

www.richardspro... - April 7, 2008 - 11:51

I had the same problem and changing $destination to $original_path fixed it.

#6

www.richardspro... - April 7, 2008 - 13:16
Status:active» patch (code needs review)

I've made a patch that implements tic2000's suggested fix in comment #4.

It's quite a simple, but I've not done a patch before, so can someone let me know it's okay.

AttachmentSize
image-223836.patch623 bytes

#7

fzwoch - April 14, 2008 - 14:47

The fix works fine for me too and seems pretty much sane.

The patch looks ok but I would have removed the redundant space right before the third argument too.

#8

CNlQ8o - April 21, 2008 - 22:36
Status:patch (code needs review)» patch (reviewed & tested by the community)

The patch works.

#9

YesCT - May 14, 2008 - 05:30

is this in the alpha release?

#10

jimmyc - May 22, 2008 - 18:18

No, it's not in the alpha release (I'm using it) nor in 6.x-1.x-dev (from what others are saying).

#11

Hetta - May 23, 2008 - 04:27

marked http://drupal.org/node/216773 as duplicate.

#12

fzwoch - July 1, 2008 - 12:57

The patch seems to be included in 6.x-1.0-alpha2 (2008-Jun-16) as well as in 6.x-1.x-dev (2008-Jun-17).

Perhaps this can be closed?

#13

drewish - July 1, 2008 - 20:45
Status:patch (reviewed & tested by the community)» duplicate

yeah looks like this and #257167: Scale and crop not working are duplicates. since that got committed i'll mark this as a dupe.

 
 

Drupal is a registered trademark of Dries Buytaert.