Topic on Project:Support desk

"Error creating thumbnail: Error code: 2"

18
129.65.56.96 (talkcontribs)

G'day,

I recently moved my MediaWiki from one server to another. Everything seems to work well except thumbnail generation: I receive "Error creating thumbnail: Error code: 2"

I have reviewed and tried the various documented online solutions without success. My LocalSettings.php is

$wgEnableUploads = true;
$wgUseImageMagick = true;
$wgImageMagickConvertCommand = "/usr/bin/convert";

I can confirm that ImageMagick is installed (version 6.7.7-10) and the convert command path works when I try it from the Mediawiki directory prompt. . MediaWiki is looking into the right place for images (full images upload and display fine). I temporarily changed permissions to 777 on /images and on /images/temp just to see if that solved a problem. It didn't. I tried specifying

$wgMaxShellMemory = 512 000; 
$wgMaxShellFileSize = unlimited;

But that didn't solve the problem. I tried specifying the /images/temp directory with $wgTmpDirectory = "$IP/images/temp"; but that didn't solve the problem either. For kicks I tried using /etc/alternatives/convert but that didn't work either. I logged out of the wiki after each change and 'hard' refreshed my browser just to make sure that I was looking at the new settings effects. My MediaWiki is in /var/www/html/wikiname. It is version 1.23.2.

Convinced that imagemagick isn't being called or exiting properly I followed the links and got:

me@star:/usr/bin$ ls -l /usr/bin/convert
lrwxrwxrwx 1 root root 25 Nov  3 17:39 /usr/bin/convert -> /etc/alternatives/convert
me@star:/usr/bin$ ls -l /etc/alternatives/convert
lrwxrwxrwx 1 root root 20 Nov  3 17:39 /etc/alternatives/convert -> /usr/bin/convert.im6
me@star:/usr/bin$ ls -l /usr/bin/convert.im6
-rwxr-xr-x 1 root root 6320 Mar  6  2014 /usr/bin/convert.im6
me@star:/usr/bin$ dpkg -S /usr/bin/convert.im6
imagemagick: /usr/bin/convert.im6

I tried changing the LocalSettings command path to /usr/bin/convert/im6 but it didn't help. I'm out of troubleshooting ideas. Any suggestions?

Ciencia Al Poder (talkcontribs)

You say you have this:

$wgMaxShellMemory = 512 000; 
$wgMaxShellFileSize = unlimited;

But Manual:$wgMaxShellFileSize doesn't mention "unlimited" as a valid value, and also I think "512 000" is not a valid number in PHP. It should generate a parse error. Could you please verify that?

129.65.56.96 (talkcontribs)

G'day, I was following (http://www.mediawiki.org/wiki/Manual_talk:Image_administration) suggestion and similar posts elsewhere reporting that this solved their similar problem even when no memory limitation was expected. I did not receive a parser error in MediWiki responses, looking in ~/apache2/error I don't see one, but I also commented out this trial after it did not resolve the problem.

This, that and the other (talkcontribs)

The fact that you didn't get a parser error with that invalid code suggests that your LocalSettings.php file is being ignored altogether...

129.65.56.96 (talkcontribs)

Thanks, but not true. Chances are good that I'm not looking in the right place for a parser error that doesn't report in the MediaWiki. LocalSettings.php is the effective configuration file because if I set #wgEnableUploads = false; then my MediaWiki doesn't allow uploads. I've sequentially tried these fixes, but either it's a 'more than one variable problem' or something else is causing an abnormal exit from ImageMagick. From the active LocalSettings.php

## To enable image uploads, make sure the 'images' directory
## is writable, then set this to true:
$wgEnableUploads = true;
$wgUseImageMagick = true;
$wgImageMagickConvertCommand = "/usr/bin/convert";
#$wgSVGConverterPath = "/usr/bin";
#$wgImageMagickTempDir = "IP$/images/temp";
#$wgMaxShellMemory = 300000;
#$wgMaxShellFileSize = 300000;
#$wgMaxShellTime = 220;
#$wgTmpDirectory = "/var/www/html/wikiname/images/temp";
#$wgUseImageReseize = true;
#$wgGenerateThumbnailOnParse = true;
##$wgSVGConverterPath = "/usr/bin";
#$wgTmpDirectory = "$IP/images/temp";
129.65.56.96 (talkcontribs)

I should have mentioned:

  • MediaWiki 1.23.2
  • PHP 5.5.9-1ubuntu4.5 (apache2handler)
  • MySQL 5.5.40-0ubuntu0.14.04.1
This, that and the other (talkcontribs)

From reading the MW source code (includes/media/Bitmap.php, line 180 or thereabouts, if you're interested), it seems that your invocation of ImageMagick is returning the error code "2".

You could try enabling the debug log: Manual:How_to_debug#Setting_up_a_debug_log_file

The log will contain lines like "transformImageMagick: running ImageMagick: " followed by the exact command line being issued by MediaWiki. You should try running this command manually (at a shell on your server) and see what happens.

In the debug log you may also see lines containing "thumbnail failed on", which may point you closer to the source of the problem.

129.65.56.96 (talkcontribs)

Thank you, that was a helpful suggestion. I made the log file and this is the relevant portion of the log:

File::transform: Doing stat for mwstore://local-backend/local-thumb/9/93/How_Did_you_Hear_About_2014.png/120px-How_Did_you_Hear_About_2014.png FileBackendStore::getFileStat: File mwstore://local-backend/local-thumb/9/93/How_Did_you_Hear_About_2014.png/120px-How_Did_you_Hear_About_2014.png does not exist. BitmapHandler::doTransform: creating 120x68 thumbnail at /tmp/transform_79944211ec2f-1.png using scaler im BitmapHandler::doTransform: called wfMkdirParents(/tmp) BitmapHandler::transformImageMagick: running ImageMagick: '/usr/bin/convert' '-quality' '95' '-background' 'white' '/var/www/html/wikiname/images/9/93/How_Did_you_Hear_About_2014.png' '-thumbnail' '120x68!' '-set' 'comment' 'File source: http://intentionallyremoved/wikiname//index.php/File:How_Did_you_Hear_About_2014.png' '-depth' '8' '-rotate' '-0' '/tmp/transform_79944211ec2f-1.png' wfShellExec: /bin/bash '/var/www/html/wikiname/includes/limit.sh' 'OMP_NUM_THREADS='\''1'\'' '\''/usr/bin/convert'\'' '\''-quality'\'' '\''95'\'' '\''-background'\'' '\''white'\'' '\''/var/www/html/wikiname/images/9/93/How_Did_you_Hear_About_2014.png'\'' '\''-thumbnail'\'' '\''120x68!'\'' '\''-set'\'' '\''comment'\'' '\''File source: http:// intentionallyremoved /wikiname//index.php/File:How_Did_you_Hear_About_2014.png'\'' '\''-depth'\'' '\''8'\'' '\''-rotate'\'' '\''-0'\'' '\''/tmp/transform_79944211ec2f-1.png'\''' 'MW_INCLUDE_STDERR=1;MW_CPU_LIMIT=180; MW_CGROUP='\'''\''; MW_MEM_LIMIT=307200; MW_FILE_SIZE_LIMIT=102400; MW_WALL_CLOCK_LIMIT=180; MW_USE_LOG_PIPE=yes'[thumbnail] thumbnail failed on star: error 2 "" from "'/usr/bin/convert' '-quality' '95' '-background' 'white' '/var/www/html/wikiname/images/9/93/How_Did_you_Hear_About_2014.png' '-thumbnail' '120x68!' '-set' 'comment' 'File source: http:// intentionallyremoved /wikiname//index.php/File:How_Did_you_Hear_About_2014.png' '-depth' '8' '-rotate' '-0' '/tmp/transform_79944211ec2f-1.png'" [thumbnail] Removing bad 0-byte thumbnail "/tmp/transform_79944211ec2f-1.png". unlink() succeeded User::getBlockedStatus: checking... ForeignAPIRepo: HTTP GET: http://commons.wikimedia.org/w/api.php?aisha1base36=2d68fauliovh2w1k57br39hr2tsvmj7&aiprop=timestamp%7Cuser%7Ccomment%7Curl%7Csize%7Csha1%7Cmetadata%7Cmime%7Cmediatype%7Cextmetadata&list=allimages&format=json&action=query&redirects=true&uselang=en LoadBalancer::reuseConnection: this connection was not opened as a foreign connection [runJobs] Running 1 job(s) via '/wikiname//index.php?title=Special%3ARunJobs&tasks=jobs&maxjobs=1&sigexpiry=1416866196&signature=e8ce801451b14a3d680b953c8d298293fdffbfeb'

I then tried to run the command as you suggested:

me@place:/var/www/html/wikiname/images$ /usr/bin/convert -quality 95 /var/www/html/wikiname/images/9/93/How_Did_you_Hear_About_2014.png -thumbnail 120x68! /var/www/html/wikiname/images/9/93/bpthumb.png convert: unable to open image `/var/www/html/wikiname/images/9/93/bpthumb.png': Permission denied @ error/blob.c/OpenBlob/2638. convert: WriteBlob Failed `/var/www/html/wikiname/images/9/93/bpthumb.png' @ error/png.c/MagickPNGErrorHandler/1728. me@place:/var/www/html/wikiname/images$

Helpful! So I then changed the permsions of ~/images and all subdirectories so that then MediaWiki user www-data has drwxr-xr-x I was then able to execute the code without an error and thumbnail file was correctly built as I can see when I downloaded it via ftp, but the MediaWiki still give me the same error code 2 and doesn't' produce thumbnails for the images (in say new files special page). I simplified the MediaWiki command to:

/usr/bin/convert -quality 95 -background white /var/www/html/wikiname/images/9/93/How_Did_you_Hear_About_2014.png -thumbnail 120x68! -depth 8 -rotate -0 /var/www/html/wikiname/images/9/93/transform_bp4.png

And I got:

convert: unable to open image `/var/www/html/wikiname/images/9/93/transform_bp4.png': Permission denied @ error/blob.c/OpenBlob/2638. convert: WriteBlob Failed `/var/www/html/wikiname/images/9/93/transform_bp4.png' @ error/png.c/MagickPNGErrorHandler/1728.

So I suspect a permissions error, but I get the same error even when I set the ~/images/9 and ~/9/93 to drwxrwxr-x

This, that and the other (talkcontribs)

Note that the original ImageMagick command seems to be trying to write to your /tmp directory. Try checking the permissions on that directory! Or try running the original ImageMagick command exactly, complete with the output filename in /tmp, and see what messages you get.

129.65.56.96 (talkcontribs)

Thanks. the /tmp directory is drwxrwxrwt. I think it should be open. By setting permissions to 777 I was able to execute the imagemagick line manually. I'm beginning to suspect that the problem is ownership or group membership or something? Most of my directions in ~/wikiname are like

drwxr-xr-x 8 me UNIVERSITY\domain^users 4096 Nov 11 16:17 extensions

but images is

drwxr-xr-x 22 me www-data 4096 Nov 11 16:17 images

because I changed ownership as advised here (http://www.mediawiki.org/wiki/Manual:Configuring_file_uploads). All the subdirectories under images are

drwxr-xr-x 16 me www-data 4096 Nov 24 12:54 9

Is this a problematic permissions configuration maybe?

This, that and the other (talkcontribs)

Unfortunately I know very little about Unix permissions, being a Windows person myself. At least in Windows you get a nice user interface to manage permissions! On Linux-based boxes it seems very confusing.

My only suggestion would be to carefully check what user the server or PHP processes are running under, and make sure they have the correct permissions. Or if you try setting the relevant directories' permissions to 777 (temporarily of course), and everything then works, it is evidently a problem of certain users not having the right permissions on the right directories. Keep checking the MediaWiki debug log for information.

Ciencia Al Poder (talkcontribs)

Confusing? unix permissions are very simple ;)

Try what TTO suggested (777 permissions), and if that also fails, the problem might be that you have some sort of security program blocking "unexpected" file creations. The most common problem is SELinux. Try disabling it.

Ciencia Al Poder (talkcontribs)

Note that every line starting with a "#" character in LocalSettings.php is ignored, since it's a PHP comment.

Note that $wgImageMagickTempDir = "IP$/images/temp"; should be $wgImageMagickTempDir = "$IP/images/temp"; instead. And the value of $wgSVGConverterPath doesn't make sense. Still, all of those configuration variables are commented out, so they aren't being used in your installation.

129.65.56.96 (talkcontribs)

Yes, thank you. I understand the commenting syntax. I was just illustrating my history of trying one fix at a time.

Sergezolotukhin (talkcontribs)

In my case, I had bash error '\r': command not found when running includes/limit.sh (this script is using for running convert). So it's easy to fix it with removing trailing \r character that causes this error:

sed -i 's/\r$//' includes/limit.sh

.digamma (talkcontribs)

Just upgraded to 1.33.0 and this (sed command on my includes/shell/limit.sh) ^^^ fixed it for me.


Awailable (talkcontribs)

Can you explain this error more? I'm sure i have that same problem...

Awailable (talkcontribs)

-

Reply to ""Error creating thumbnail: Error code: 2""