I am trying to use the Image Attach module to create a story node, upload an image, and attach the image to the story node in a single operation. It isn't working. When I click the Save button I get a divide-by-zero error.
The symptoms are slightly different when running under Windows (my development system) and Linux (my client's host).
Under Windows I get two error messages which say:
Warning: Division by zero in /export/home/.../modules/image/image.module on line 198.
Unable to create scaled Thumbnail image
Drupal saves the original image but does not create the thumbnail image (or the preview image). When I display the story to which the image is attached, I get the following messages, but still no thumbnail (that being the version of the image which the story tries to display):
filename.jpg's thumbnail derivative image was missing. The derivatives will be rebuilt to regenerate it.
filename.jpg's preview derivative image was missing. The derivatives will be rebuilt to regenerate it.
The derivative images for filename.jpg have been regenerated.
Unable to create scaled Thumbnail image
Under Linux I get only the "Division by zero in..." message (not the "Unable to create scaled..." message). When I try to display the node I get no warning messages, but still no thumbnail.
If I upload the image to an Image node and then attach the uploaded image to the story in a separate operation, I have no trouble under either system.
I was originally unable to try this at all under Linux because I couldn't get it working on my Windows development system. Since other people were having no trouble I assumed it was a compatibility problem between Image Attach and Windows, and that the developers would flush it out quickly once it was brought to their attention. Now that I know it fails on both systems, the problem seems to require a different approach.
I don't know what is wrong, but I have a theory. My site needs to size the thumbnail to a fixed height (80 pixels). Thus, in Home » Administer » Site configuration, the Thumbnail height is set to 80 and the width is unset, i.e., 0. Try to compute a scale factor by dividing the original images width by the width specified for the thumbnail, and you get... what I got.
Comments
Comment #1
Oval commentedHave you checked whether this is simply a problem with GD not being installed on either system, or maybe permissions? Check your "Image Toolkit" page and see if you get any errors.
The division by zero error shouldn't be there though.
Comment #2
orthoducks commentedIt appears you're correct that GD is not installed. It's not listed in the phpInfo configuration section, and it's not in the INI file or the extension directory.
I never would have considered that possibility if you hadn't suggested it. Since Drupal processes the images correctly when I upload them and attach them in separate steps, I didn't see how the GD extension could possibly be absent (and I still don't).
Having gotten this far, I need to ask a couple more questions.
First, where can I find the extension I need for my Windows environment (I believe it is php_gd2.dll)? It's not in my extension directory. I think it should be somewhere on the php.net web site -- I'd hesitate to download it from somewhere else -- but I can't find it there. There's nothing about extensions on the Downloads page. I tried searching the site for the file name, but I couldn't find a download; just a few references to documentation and a bunch of bug reports.
Second: I don't think I'll have difficulty adding the extension to my own PHP, but how can I add it to my client's host's Linux system, where I don't even have shell access? The host is often unresponsive to requests for additional resources. If there is some way I can add the extension to the client's environment using only FTP, it will probably be much easier than asking them to do it.
Comment #3
orthoducks commentedI thought I had figured out how to load GD2. Further debugging showed me that I had not, but I couldn't figure out what was wrong. I revisited the changes I made to PHP.INI, which looked right when I made them; they still looked right, but phpInfo didn't list the extension.
In php.ini I tried changing "extension=php_gd2.dll" to "extension=php_gd.dll," and that worked. Both DLLs are in the extension directory. I'd dearly love to know why GD loads and GD2 won't. Meanwhile, though, onward.
I found that apart from the missing GD extension, there were several problems in the code. I have figured out how to fix all of them except one: when I delete a story with an attached image, the image is not deleted.
I realize that in the general case this is correct behavior; the image might be used in more than one story, and if it's not, someone might want to use it later. In my current project that will never be the case, though, and I need to ensure that the attached image node will be deleted when the story is.
I've been trying to accomplish this through a hook_node_type function, which seems like the right approach to me. It's not working, though; see http://drupal.org/node/274261. I'm open to alternatives.
I'll document the problems I found, and my fixes for them, when I'm done. That should happen within a few days. My changes are hacks, but they ought to suggest clean fixes to someone who is familiar with the code.
Comment #4
coltraneReseting title.
Comment #5
sunSorry, unfortunately this request is way too specific. Please have a look at the issue queue - Image maintainers are buried already. You might want to try to get further support at http://drupal.org/support. Additionally, the answer to your question might be covered in the handbooks at http://drupal.org/handbook/modules/image already.
If you were able to solve this issue on your own in the meantime, you might want to add the involved steps to this closed issue, so other users searching for a similar solution might find it.