ImageMagick on Ubuntu 14.04 No decode delegate - ubuntu-14.04

In development enviroment works but not in production enviroment.
Production enviroment error:
$e->getMessage():
"no decode delegate for this image format
'/tmp/sws5725c638311df5.24370631' # error/svg.c/ReadSVGImage/2871"
Generate tmpname:
$tmpname = '/tmp/'.uniqid('sws', true);
Method:
public function load($filename)
{
try
{
$this->filename = $filename;
$this->image = new Imagick($filename);
return $this;
}
catch(ImagickException $e)
{
error_log($e->getMessage(), 3, "/tmp/log.log");
OPException::raise(new OPInvalidImageException('Could not create jpeg with ImageMagick library'));
}
}
Delegates:
convert -list configure | grep DELEGATES
bzlib djvu fftw fontconfig freetype jbig jpeg jng jp2 lcms2 lqr lzma openexr pango png rsvg tiff x11 xml wmf zlib
Versions (dev and prod enviroments):
ImageMagick 6.7.7-10
Ubuntu 14.04
PHP 5.5.9-1ubuntu4.16
Any suggestions? Thanks for your attention.

Temporary file
In reviewing the temporary file with the command vim I got the error message coming from the server in XML format and is why the library imagick treated it as svg file.
vim /tmp/sws5725c638311df5.24370631
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>RequestTimeTooSkewed</Code>
<Message>The difference between the request time and the current time is too large.</Message>
<RequestTime>Sun, 01 May 2016 06:43:17 GMT</RequestTime>
<ServerTime>2016-05-01T06:28:06Z</ServerTime>
<MaxAllowedSkewMilliseconds>900000</MaxAllowedSkewMilliseconds>
<RequestId>382A337F3660C5A9</RequestId>
<HostId>+2RI3xW5KBd64P13x4yaWly6VdZzn1okvMAYgKvbFYlGnLp87udxpSBCVx7iQNk7zgnkK/ckUXA=</HostId>
</Error>
Solution
Synchronize time operating system with the server time.
sudo service ntp stop
sudo ntpdate ntp.ubuntu.com
sudo service ntp start
Thanks for the comments.

Related

highcharts-export-server does not finish

I have highcharts-export-server v2.1.0 (which uses phantomjs v.2.1.1) configured on 2 servers.
Problem: One server can produce a chart from my "test" .json to .svg, the other server cannot / seems stuck...
Question: I have already set the logLevel to 4, How else can I debug this / find the error?
.
My input script is the following:
{"title":{"text":"Benchmark +0.75% (Year to Date)"},"time":{"useUTC":false},"chart":{"alignThresholds":true,"width":1000,"height":400,"plotBackgroundColor":null,"plotBorderWidth":0,"plotShadow":false,"spacingRight":40},"xAxis":{"labels":{"rotation":-45}},"yAxis":[{"labels":{"format":"{value:.0f}"},"showLastLabel":true,"opposite":false,"min":-3.67256505,"max":4.93075599694519,"tickPositions":[-3.67,-2.6,-1.52,0,0.63,1.7,2.78,3.86,4.93]},{"showLastLabel":true,"gridLineWidth":0,"tickPosition":"outside","labels":{"align":"right","x":30,"style":{"color":"#ff0000"}},"min":-0.9340809915870241,"max":1.2540895500000002,"tickPositions":[-0.93,-0.66,-0.39,-0.11,0,0.16,0.43,0.71,0.98,1.25]}],"legend":{"enabled":true},"rangeSelector":{"enabled":false},"scrollbar":{"enabled":false},"navigator":{"enabled":false},"credits":{"enabled":false},"plotOptions":{"series":{"compare":"percent","showInNavigator":false}},"series":[{"compare":"amount","data":[[1609282800000,0],[1609369200000,-0.03428646532872559],[1609455600000,-0.0016039750283303178],[1609714800000,0.7637526405996908],[1609801200000,0.8005732883660022],[1609887600000,-0.1690494144598209],[1609974000000,-0.3809350266101741],[1610060400000,-1.514325071693856],[1610319600000,-0.4765023006985114],[1610406000000,-0.20592306146072215],[1610492400000,-1.6056700749591757],[1610578800000,-2.283907756098269],[1610665200000,-2.8475657141212585],[1610924400000,-2.5301565339659216],[1611010800000,-1.347913879404139],[1611097200000,-1.078254441804205],[1611183600000,-1.508647334728952],[1611270000000,-1.5661224299388987],[1611529200000,-2.280813980426055],[1611615600000,-1.9904069262878465],[1611702000000,-3.1733261828598924],[1611788400000,-2.6038661425901943],[1611874800000,-3.10474672552985],[1612134000000,-1.9489382228070617],[1612220400000,-1.4168123948971045],[1612306800000,-1.5077205238559155],[1612393200000,-1.114743473256452],[1612479600000,-1.445007216058669],[1612738800000,-1.2708019773828516],[1612825200000,-1.5637751417799883],[1612911600000,-0.9207988194119499],[1612998000000,-0.5330477534657541],[1613084400000,-1.3483873661346957],[1613343600000,-1.2824277237734494],[1613430000000,-0.8192853328358063],[1613516400000,-0.3653079990091568],[1613602800000,-0.060653517166342485],[1613689200000,0.8697340876174797],[1613948400000,1.2280953226873725],[1614034800000,1.0859394764373809],[1614121200000,1.2063367293352778],[1614207600000,0.10773414212172927],[1614294000000,-1.5207190905506263],[1614553200000,-0.9816998314673975],[1614639600000,-0.924383129032802],[1614726000000,-0.8715904396361718],[1614812400000,-0.4280745420743859]],"name":"Portfolio -0.43%"},{"compare":"amount","data":[[1609282800000,0],[1609714800000,0.8278755650112268],[1609801200000,0.7356135496841887],[1609887600000,-0.3448445224439989],[1609974000000,-0.5651564695949629],[1610060400000,-1.6946417469431263],[1610319600000,-0.6017716353404978],[1610406000000,-0.302437374178699],[1610492400000,-1.6516136459999498],[1610578800000,-2.459423156169538],[1610665200000,-2.696698045145274],[1610924400000,-2.410809781870449],[1611010800000,-1.3613816021318614],[1611097200000,-0.991919709902811],[1611183600000,-1.414545878781237],[1611270000000,-1.4817771059954743],[1611529200000,-2.3322008861873744],[1611615600000,-2.036590278127237],[1611702000000,-3.4976807891963],[1611788400000,-2.986102839764737],[1611874800000,-3.4540325607614886],[1612134000000,-2.105269707267987],[1612220400000,-1.5899676921416361],[1612306800000,-1.7726301025414615],[1612393200000,-1.5556279775712611],[1612479600000,-1.7695269895245613],[1612738800000,-1.655544008265486],[1612825200000,-1.93170951416185],[1612911600000,-1.2587762893416121],[1612998000000,-0.8789710996493616],[1613084400000,-1.718017623965562],[1613343600000,-1.6160328512600741],[1613430000000,-1.1553433147096226],[1613516400000,-0.8357362895423104],[1613602800000,-0.5901872577077749],[1613689200000,0.4652404389007492],[1613948400000,0.7387166627010888],[1614034800000,0.6296984147131646],[1614121200000,0.597220732990178],[1614207600000,-0.45944804378783566],[1614294000000,-1.952809940009137],[1614553200000,-1.430060618679485],[1614639600000,-1.3313860807479094],[1614726000000,-1.3636570533070103],[1614812400000,-1.622445786457749],[1614898800000,-1.5049462738540242],[1615158000000,-1.1762370313930126]],"name":"BENCHM REF -1.18%"},{"data":[[1609282800000,0],[1609714800000,-0.064122924411536],[1609801200000,0.06495973868181348],[1609887600000,0.17579510798417797],[1609974000000,0.18422144298478882],[1610060400000,0.1803166752492702],[1610319600000,0.12526933464198642],[1610406000000,0.09651431271797684],[1610492400000,0.04594357104077407],[1610578800000,0.17551540007126887],[1610665200000,-0.1508676689759847],[1610924400000,-0.11934675209547274],[1611010800000,0.013467722727722453],[1611097200000,-0.08633473190139407],[1611183600000,-0.09410145594771491],[1611270000000,-0.08434532394342442],[1611529200000,0.05138690576131921],[1611615600000,0.046183351839390596],[1611702000000,0.3243546063364078],[1611788400000,0.3822366971745428],[1611874800000,0.3492858352316386],[1612134000000,0.15633148446092537],[1612220400000,0.1731552972445316],[1612306800000,0.264909578685546],[1612393200000,0.4408845043148091],[1612479600000,0.3245197734658922],[1612738800000,0.38474203088263437],[1612825200000,0.3679343723818618],[1612911600000,0.33797746992966227],[1612998000000,0.34592334618360754],[1613084400000,0.36963025783086634],[1613343600000,0.33360512748662474],[1613430000000,0.3360579818738163],[1613516400000,0.4704282905331536],[1613602800000,0.5295337405414324],[1613689200000,0.40449364871673055],[1613948400000,0.4893786599862837],[1614034800000,0.4562410617242163],[1614121200000,0.6091159963450998],[1614207600000,0.5671821859095649],[1614294000000,0.43209084945851073],[1614553200000,0.4483607872120876],[1614639600000,0.4070029517151075],[1614726000000,0.4920666136708385],[1614812400000,1.1943712443833632]],"color":"#ff0000","name":"Relative Performance +0.75%","yAxis":1,"compare":"amount","dashStyle":"ShortDash"}]}
This is the code I use to produce the .svg file
/opt/mx/reports/node_modules/highcharts-export-server/bin/cli.js -infile /opt/mx/reports/js/_testcases/stock.json -outfile /tmp/_teststockchart.svg -type svg -constr StockChart --logLevel 4
This is the .svg being produced:

AWS Lambda function - convert PDF to Image

I am developing application where user can upload some drawings in pdf format. Uploaded files are stored on S3. After uploading, files has to be converted to images. For this purpose I have created lambda function which downloads file from S3 to /tmp folder in lambda execution environment and then I call ‘convert’ command from imagemagick.
convert sourceFile.pdf targetFile.png
Lambda runtime environment is nodejs 4.3. Memory is set to 128MB, timeout 30 sec.
Now the problem is that some files are converted successfully while others are failing with the following error:
{ [Error: Command failed: /bin/sh -c convert /tmp/sourceFile.pdf
/tmp/targetFile.png convert: %s' (%d) "gs" -q -dQUIET -dSAFER -dBATCH
-dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" "-sOutputFile=/tmp/magick-QRH6nVLV--0000001" "-f/tmp/magick-B610L5uo"
"-f/tmp/magick-tIe1MjeR" # error/utility.c/SystemCommand/1890.
convert: Postscript delegate failed/tmp/sourceFile.pdf': No such
file or directory # error/pdf.c/ReadPDFImage/678. convert: no images
defined `/tmp/targetFile.png' #
error/convert.c/ConvertImageCommand/3046. ] killed: false, code: 1,
signal: null, cmd: '/bin/sh -c convert /tmp/sourceFile.pdf
/tmp/targetFile.png' }
At first I did not understand why this happens, then I tried to convert problematic files on my local Ubuntu machine with the same command. This is the output from terminal:
**** Warning: considering '0000000000 XXXXX n' as a free entry.
**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Mac OS X 10.10.5 Quartz PDFContext <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.
So the message was very clear, but the file gets converted to png anyway. If I try to do convert source.pdf target.pdf and after that convert target.pdf image.png, file is repaired and converted without any errors. This doesn’t work with lambda.
Since the same thing works on one environment but not on the other, my best guess is that the version of Ghostscript is the problem. Installed version on AMI is 8.70. On my local machine Ghostsript version is 9.18.
My questions are:
Is the version of ghostscript problem? Is this a bug with older
version of ghostscript? If not, how can I tell ghostscript (with or
without using imagemagick) to repair or ignore errors like it does on
my local environment?
If the old version is a problem, is it possible to build ghostscript
from source, create nodejs module and then use that version of
ghostscript instead the one that is installed?
Is there an easier way to convert pdf to image without using
imagemagick and ghostscript?
UPDATE
Relevant part of lambda code:
var exec = require('child_process').exec;
var AWS = require('aws-sdk');
var fs = require('fs');
...
var localSourceFile = '/tmp/sourceFile.pdf';
var localTargetFile = '/tmp/targetFile.png';
var writeStream = fs.createWriteStream(localSourceFile);
writeStream.write(body);
writeStream.end();
writeStream.on('error', function (err) {
console.log("Error writing data from s3 to tmp folder.");
context.fail(err);
});
writeStream.on('finish', function () {
var cmd = 'convert ' + localSourceFile + ' ' + localTargetFile;
exec(cmd, function (err, stdout, stderr ) {
if (err) {
console.log("Error executing convert command.");
context.fail(err);
}
if (stderr) {
console.log("Command executed successfully but returned error.");
context.fail(stderr);
}else{
//file converted successfully - do something...
}
});
});
You can find a compiled version of Ghostscript for Lambda in the following repository.
You should add the files to the zip file that you are uploading as the source code to AWS Lambda.
https://github.com/sina-masnadi/lambda-ghostscript
This is an npm package to call Ghostscript functions:
https://github.com/sina-masnadi/node-gs
After copying the compiled Ghostscript files to your project and adding the npm package, you can use the executablePath('path to ghostscript') function to point the package to the compiled Ghostscript files that you added earlier.
Its almost certainly a bug, or perhaps limitation, with the older version of Ghostscript.
Many PDF producers create PDF files which do not conform to the specification, and yet will open without complain in Adobe Acrobat. Ghostscript endeavours to do the same, but obviously we can't know what Acrobat is going to allow, so we are continually chasing this nebulous target. (FWIW that warning is a legitimate out-of-spec PDF file).
There's nothing you can do with the old version other than replace it.
Yes you can build Ghostscript from source, I have no idea about a nodejs module, not sure why that's relevant.
There are numerous other applications which will render a PDF file, MuPDF is another one I know of. And, of course, you can use Ghostscript directly without using ImageMagick. Of course, if you can load another application, then you should simply be able to replace your Ghostscript installation too.
The version of GS on aws is an old version with known bugs. We can get around this by uploading an x64 GS file, compiled specifically for Linux. Then upload that using new AWS lambda layers. I have written a node function that does just this here:
https://github.com/rcastoro/PDFImagine
Make sure you have that GS layer for your lambda, however!

Imagick : SVG to PNG conversion giving me blank png image

I have a SVG image on this path http://www.quickdesign.com/user-uploads/5555f546857ce-saved.svg
Which i need to convert into PNG for which i am using below code on this php file http://www.quickdesign.com/png.php
<?php
$svg_file_name = 'user-uploads/5555f546857ce-saved.svg';
$png_file_name = 'png/converted.png';
$im = new Imagick();
$im->setBackgroundColor(new ImagickPixel('transparent'));
$svg = file_get_contents($svg_file_name);
$svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.$svg;
$im->readImageBlob($svg);
/*png settings*/
$im->setImageFormat("png32");
$im->writeImage($png_file_name);
header('Content-type: image/png');
echo $im;
$im->clear();
$im->destroy();
?>
If i remove the line $svg = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>'.$svg; Then it gives fatal error Uncaught exception 'ImagickException' with message 'no decode delegate for this image format
Can anyone please help me how to convert above svg image to PNG image using PHP.
Any help would be appreciated.
Thanks
ImageMagick uses delegates to read some images. It looks like the delegate it is using for SVG files on your system is unable to the SVG file you are telling it to read.
Reading that file also fails on my system due to this bit:
<stop fill="url(#svg_14)" stop-color="#A0D9F7" offset="0"/>
with the error message:
php: unrecognized color `svg_14' # warning/color.c/GetColorCompliance/1046.
php: unable to open image `svg_14': No such file or directory # error/blob.c/OpenBlob/2674.
php: no decode delegate for this image format `' # error/constitute.c/ReadImage/501.
url support inside SVG files is a bit flaky. It seems that svg_14 is defined at the end of the file. Moving it to the start makes the file be 'readable' but the image looks different to how it should appear.
I would suggest finding out what delegate ImageMagick is using to decode SVG files, which may be found with convert -list configure and finding if there is a more recent version of that library which fixes the issue.

pdf2swf couldn't create a font for 'SimSun'

I was trying to convert a pdf into a swf and i was using swftools. To support Chinese, i downloaded xpdf-chinese-simplified.tar and modified the add-to-xpdfrc file like this
#----- begin Chinese Simplified support package (2011-sep-02)
cidToUnicode Adobe-GB1 /usr/local/share/xpdf-chinese-simplified/Adobe-GB1.cidToUnicode
unicodeMap ISO-2022-CN /usr/local/share/xpdf-chinese-simplified/ISO-2022-CN.unicodeMap
unicodeMap EUC-CN /usr/local/share/xpdf-chinese-simplified/EUC-CN.unicodeMap
unicodeMap GBK /usr/local/share/xpdf-chinese-simplified/GBK.unicodeMap
cMapDir Adobe-GB1 /usr/local/share/xpdf-chinese-simplified/CMap
toUnicodeDir /usr/local/share/xpdf-chinese-simplified/CMap
#fontFileCC Adobe-GB1 /usr/..../gkai00mp.ttf
displayCIDFontTT Adobe-GB1 /usr/local/share/xpdf-chinese-simplified/gkai00mp.ttf
#----- end Chinese Simplified support package
When i tried to convert the pdf,
/usr/local/bin/pdf2swf 10434_102_demo_1414995035745.pdf -o test.swf -s
languagedir=/usr/local/share/xpdf-chinese-simplified
an error occured:
Error: Couldn't create a font for 'SimSun'
PS. I have two environments, one is MAC and the other is Redhat, everything is ok in MAC and this error only occurs in Redhat.
As this question is missing an answer, I can add an optional solution (as a workaround) here.
For Flexpaper, if you use the "HTML5" render mode, it will render Chinese, and other unicode text, correctly.

encfs decryption, filename encoding 'nameio/block' 4.0.0 not supported

I'm trying to decrypt an encfs folder, but when executing the command I get the following error:
(FileUtils.cpp:1649) Unable to find nameio interface nameio/block, version 4:0:0
The command I use for mounting is simply:
encfs ~/encrypted_folder ~/mount_point
I've tried with sudo or --forcedecode, got same result.
the output for the encfsctl command over the encrypted folder is:
Version 6 configuration; created by EncFS 1.7.5 (revision 20100713)
Filesystem cipher: "ssl/aes", version 3:0:0 (using 3:0:2)
Filename encoding: "nameio/block", version 4:0:0 (NOT supported)
Key Size: 256 bits
Using PBKDF2, with 1351653 iterations
Salt Size: 160 bits
Block Size: 1024 bytes, including 8 byte MAC header
Each file contains 8 byte header with unique IV data.
Filenames encoded using IV chaining mode.
File data IV is chained to filename IV.
File holes passed through to ciphertext.
My OS details are:
Ubuntu 14.04.1 LTS with kernel 3.13.0-35-generic
I'm pretty lost, I don't know what is that encoding and why is not supported. Searching on google does not give me any solutions...
Confimed: using encfs 1.7.5 solves the problem.

Resources