When I go to `admin/config/media/image-styles/edit/medium`, I get this error:

    Warning: Division by zero in theme_image_style_preview() (line 786 of /home/naught101/Documents/enviro/hcec/ElectionScoreCard/website/modules/image/image.admin.inc).
    Warning: array_intersect_key(): Argument #1 is not an array in theme_image_style_preview() (line 788 of /home/naught101/Documents/enviro/hcec/ElectionScoreCard/website/modules/image/image.admin.inc).

This happens for all the default styles.

I'm running drupal 7.x-1.x (git, up to date as of a few minutes ago) with no image related modules (modules available installed are `admin_menu, ctools, devel, entity, fivestar, geophp, markup, openlayers_field, proj4js, relation, token, views_hacks, coder, date, efq_views, field_collection, geofield, libraries, openlayers, pathauto, rate, relation_add, views, votingapi`). Drupal is running on kubuntu raring. Relevant parts of status report:

Drupal                                    7.23-dev
Install profile                           Minimal (minimal-7.23-dev)
CTools CSS Cache                          Exists
Database system                           MySQL, MariaDB, or equivalent
Database system version                   5.5.31-0ubuntu0.13.04.1
GD library rotate and desaturate effects  2.0
PHP                                       5.4.9-4ubuntu2 (more information)
PHP extensions                            Enabled
PHP memory limit                          256M
Web server                                Apache/2.2.22 (Ubuntu)
CommentFileSizeAuthor
#3 broken_image_filter_divide_by_zero.png97.59 KBnaught101

Comments

donutdan4114’s picture

Do you have a sample.png file in your image module folder? If that file is not there, or has non-read permissions, the division by zero error will occur.

donutdan4114’s picture

Status: Active » Fixed

I'm going to mark that as fixed unless you can reproduce this with the sample.png file existing.

naught101’s picture

Status: Fixed » Active
StatusFileSize
new97.59 KB

The image is there:

$ ls modules/image/sample.png -lah
-rw-rw-r-- 1 naught101 naught101 165K Nov 11 09:26 modules/image/sample.png

It even shows on the page:
broken_image_filter_divide_by_zero.png

I have even tried chmod a+rwx modules/image/sample.png, and that doesn't work either. Permissions are clearly not the problem. Also, the image reads fine (in the browser and in gwenview), so it's not broken. git status shows no changes except added modules in sites/all/modules.

I understand that this is probably a set-up problem, and I'm thinking that it's because I moved to raring, but I don't really know where to start looking for the root cause.

johncs’s picture

I have this same problem in 7.22
Here is my research:
I added some debugging code to drupal/modules/image/image.admin.inc

774   // Set up preview file information.
775   ob_start();
776   $preview_file = image_style_path($style['name'], $original_path);
777   print "<br> File: " .  $preview_file;
778   if (!file_exists($preview_file)) {
779     image_style_create_derivative($style, $original_path, $preview_file);
780     print "<br> now: " .  $preview_file;
781   }
782   if (!file_exists($preview_file)) {
783     print "<br> " . $preview_file . " still doesn't exist";
784   }
785   $preview_image = image_get_info($preview_file);
786 
787   print "<br> preview_image: ";
788   var_dump($preview_image);
789   print "<br> width: " .  $preview_image['width'];
790   drupal_set_message(ob_get_clean());

I discovered the file does not exist, and line 783 is executed.

I used strace on Apache:
[code]
strace -f -e trace=file -o /tmp/trace-httpd $(ps xa | awk '/httpd/ {print "-p " $1}')

I grepped the trace and located sample.png

09:59 [root@WebServer ~]# grep sample  /tmp/trace-httpd
5712  stat("modules/image/sample.png", {st_mode=S_IFREG|0644, st_size=168110, ...}) = 0
5712  lstat("/var/www/sites/chesswa/drupal/modules/image/sample.png", {st_mode=S_IFREG|0644, st_size=168110, ...}) = 0
5712  open("/var/www/sites/chesswa/drupal/modules/image/sample.png", O_RDONLY) = 15
5712  stat("modules/image/sample.png", {st_mode=S_IFREG|0644, st_size=168110, ...}) = 0
5712  lstat("/var/www/sites/chesswa/drupal/sites/default/files/styles/thumbnail/public/modules/image/sample.png", 0x7fffc26d5690) = -1 ENOENT (No such file or directory)
5712  open("/var/www/sites/chesswa/drupal/modules/image/sample.png", O_RDONLY) = 15
5712  open("/var/www/sites/chesswa/drupal/modules/image/sample.png", O_RDONLY) = 15
5712  lstat("/var/www/sites/chesswa/drupal/sites/default/files/styles/thumbnail/public/modules/image/sample.png", 0x7fffc26d5690) = -1 ENOENT (No such file or directory)
5712  lstat("/var/www/sites/chesswa/drupal/sites/default/files/styles/thumbnail/public/modules/image/sample.png", 0x7fffc26d5660) = -1 ENOENT (No such file or directory)
5655  stat("/var/www/sites/chesswa/drupal/sites/default/files/styles/thumbnail/public/modules/image/sample.png", 0x7fffc26dc8e0) = -1 ENOENT (No such file or directory)
5653  stat("/var/www/sites/chesswa/drupal/sites/default/files/styles/thumbnail/public/modules/image/sample.png", 0x7fffc26dc8e0) = -1 ENOENT (No such file or directory)
10:00 [root@WebServer ~]# locate sample.png
/var/www/sites/chesswa/drupal/modules/image/sample.png
donutdan4114’s picture

What are your permissions for the default/files directory?
For the image style to be created, Apache needs to be able to create directories and save images in there.

naught101’s picture

Yep, that was the problem in my case, thanks donutdan4114. Not sure whether this should be closed, because it's my fault that the permissions were screwed, or left open because the error message isn't very intuitive...

donutdan4114’s picture

I agree, the error message isn't clear.

However, to have a specific error message for every type of thing, like missing image, bad folder permission, bad file permission, etc... I think all places on the site assume folder/file permissions are set properly.

In fact, if you had checked /admin/config/media/file-system, it probably would have shown an error relating to your public folder permissions. Not sure.

naught101’s picture

naught101’s picture

Issue summary: View changes

Updated issue summary.

skribbz14’s picture

Setting "sites/default/files/styles" permissions to 775 fixed the issue for me. Thanks naught101.