This is the first time I use PHP Imagick and experiencing problems with it.
I'm creating a website module where users can upload images that need to be converted to an encrypted file type containing the uploaded image as a DDS texture.
So what I need to do is convert the uploaded image to dds file format.
Code:
$img = new Imagick('test.png'); //Load the uploaded image
$img->setformat('dds'); //Set the format to dds
$img->setImageCompression(Imagick::COMPRESSION_DXT3); //Set compression method
$img->writeimage('test.dds'); //Write/save the dds texture
The problem: the output file is always an empty, 0 byte file.
PNG That needs to be converted: test.png
DDS That needs to be the output: test.dds
Maybe I need other version Imagick or ImageMagick?
My old version of these are:
PHP 5.5.15
Imagick 3.1.2-5.5-ts-vc11-x86
ImageMagick 6.8.4-0-Q16-x86
I am currently testing on Windows 8.1 x64.
Any suggestion/help would be appreciated.
Edit: Edited the question, hopefully its clear now what I am trying to achieve.
Solved: The problem was the version of ImageMagick that had no support for DDS write.
Installed ImageMagick 6.8.6-10-Q16-x86 since the DDS write support was added in that version (newer versions caused the imagick not to be loaded).
Current version of what I use and works:
PHP 5.5.15
Imagick 3.1.2-5.5-ts-vc11-x86
ImageMagick 6.8.6-10-Q16-x86
From the debugging above the issue is that your version of ImageMagick doesn't support writing DXT3 compressed DDS files.
The options to solve this problem are:
Use a different compression format - DXT5 might be okay, but it's not exactly the same as DXT3.
Upgrade to a newer version of ImageMagick and Imagick that support writing in DXT3 format.
Related
I'm trying to convert a pdf on my local computer to a jpg file and then using Tesseract to read the image text. Simply testing code like this:
$pdf = new Pdf('C:\testing\test.pdf');
$pdf->saveImage('C:\testing\test.jpg');
$tess = new TesseractOCR('C:\testing\test.jpg');
$myresults = $tess->run();
$this->vars['result'] = $myresults;
Produces the following error:
PDFDelegateFailed `The system cannot find the file specified. ' # error/pdf.c/ReadPDFImage/794
I am using the following for my scenario:
OctoberCMS/Laravel
PHP 7.2.34 64 bit
Ghostscript 9.53.3 64 bit (32 bit didn't work either)
ImageMagick 7.0.7-11 Q16 x64
Xampp
Windows 10 64 bit
When I try converting a jpg to a png, ImageMagick works fine, but as soon as I try a PDF, I get the error. I have looked and tried solutions with little luck. I know the issue is most likely Ghostscript, as many have reported that it's the one that gives the most headaches on Windows 10, but I have no idea where to even begin trying to connect it to ImageMagick.
Any help, please?
Well, I did end up finding a workaround for this. Instead of using ImageMagick with Ghostscript, I ended up just using Ghostscript on its own. The conversion works flawlessly without issues.
I noticed that each time I save a jpg file in PHP, it is saved with sub-sampling. How to remove that? I'm using GD library.
I believe newer versions of libgd disable chroma-subsampling if you set the quality to 90 or higher.
Failing that, you could consider using PHP Imagick and disabling chroma sub-sampling with:
$img->setSamplingFactors(array('1x1', '1x1', '1x1'));
I have PHP code running on Debian stretch with ImageMagick. It tries to convert SVG to another format. Here is how it starts
$im = new Imagick();
$im->readImageBlob($svg);
The variable $svg contains valid SVG code in a string. If I copy this string to a text file with a .svg extension then it opens just fine. But readImageBlob throws an exception saying no delegate for this image format.
I have seen similar questions solved by installing more packages to the system. But I've already installed libxml2-dev, librsvg2-bin, libmagickcore-6.q16-3-extra and libfreetype6-dev.
I have no idea what else I am missing.
I had to prepend the $svg with <?xml version="1.0" ?> and it worked. It least it does read in the SVG and attempts to create png/jpeg. One piece of text gets misplaced during convertion though. So the task in general is still failed. But this is another issue. I think the question is answered.
What do you get from running the following command from PHP exec()
convert -list format
The line SVG should say RSVG or MSVG/XML. Does it show that? if you need RSVG, you will have to install that delegate and then reinstall Imagemagick so that Imagemagick can find it. Imagemagick is used by Imagick. They are not the same. The RSVG delegate can be found by a Google Search or from linuxfromscratch.org/blfs/view/svn/general/librsvg.html. Your svg file seems to render properly for me in Imagemagick using RSVG, but I am not sure what it should look like. It is just a graph set of horizontal lines.
I do not know much about using readImageBlob(). Just use readImage(), where you supply the path to a saved svg image file. That should work. Try that and see what you get.
Here is what I get using RSVG 2.42.2 in Imagemagick 6.9.10.3 Q16 Mac OSX were I have saved your text in a file called test.svg.
convert test.svg test.png
If I force the use of the Imagemagick MSVG/XML, it does not look as good.
convert MSVG:test.svg test2.png
I am using a PHP Thumbnail Generating script that I have used without issue many times in the past. I am currently using it without issue on the very same domain that I am now having problems.
The script is processing to a point. It is generating physical thumbnail images and saving them into the preset cache directory but it is not returning resized images to the browser.
The image src is in the following format:
<img src="thumbnail.php?file=sample/02.jpg&w=100&h=70&el=0&gd=0" />
I have confirmed that the image exists and can be displayed in a browser itself.
Also, the PHP script loads ok as I have tested it by adding an 'echo' to confirm.
I have installed this script in multiple locations on the server and the result is the same. I have even tried other versions of PHP Thumbnail Generators and none of them produce resized images in the browsers.
I have checked that GD is active on my server:
GD Support enabled
GD Version bundled (2.1.0 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.4.2
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version 1.2.44
WBMP Support enabled
XBM Support enabled
PHP is version 5.3.29
Imagemagick is available and path confirmed as '/usr/bin/convert/'.
Here you see the result:
http://demos.mitey.co.nz/image_processor/index.php
All that appears is broken image placeholders instead of the dynamically generated thumbnails.
All relevant permissions have be set to 0777 or 0755, tried both.
This really isn't a difficult script to use and I have numerous times in the past but I am unable to debug whatever is causing it to fail in this instance.
Anybody have any ideas as to what could be stopping the image source from correctly processing the PHP contained within it?
I have tried so many different things that I can no longer focus on the issue and come up with anything else to try.
SOLVED: I was trying to load images into the script from another sub-domain. The Thumbnail script I was using claims to allow loading images from another domain using http however it thens fails when it comes to the PHP function 'file_exists' which does not work via the http protocol. I removed the 'http://' part of the image path using 'str_replace' and replaced it with the file system path, i.e. /home/siteroot/' and all works as expected. When used with images on the same domain as the thumbnail generating script the script is happy for the full 'http://' path to remain. There was no useful error messages to point this out.
Download the latest PHPthumb from website
For generate thumb see documentation
don't forget to Change variable as per your need.
$thumbUrl = "somefolder/new.jpg";
$resizeWidth = "70"; // in pixels
$resizeHeight = "70"; // in pixels
$imageThumb = $directoryPath. "/phpThumb/phpThumb.php?src=" . $thumb1 . "&w=".$resizeWidth."&h=".$resizeHeight."&iar=1&hash=90e9d46c4d138a72574c52e31fbef0dc";
echo '<img src="'.$imageThumb.'" alt="filename.jpg" />';
I found that I did not have PNG support in my Imagick installation, so I installed libpng. Now I can see that PNG format is supported when I run a command
convert -list format
And conversion from PNG to JPG works fine from command line:
convert a.png b.jpg
But when I try to read a PNG file in PHP:
$src = new \Imagick();
$src->readImageBlob( file_get_contents($file) ); // reading PNG format
-it gives me Error 500 ("...no decode delegate for this image format")
Also when I run phpinfo() - I see no PNG in list of Imagick's supported file formats. There are many others, but no PNG.
I tried to I resintall PHP Imagick driver and then restart apache - still no succeess.
PS: I have PHP 5.4 # CentOS
According to the installation requirements. "The amount of formats supported is by Imagick is entirely dependent upon the amount of formats supported by your ImageMagick installation." I imagine you’ll need to rebuild the PHP imagemagick extension. See here: http://php.net/manual/en/imagick.installation.php
Problem solved.
I used a guide for Imagick installation #CentOS from the link below, reinstalled everything exactly as it said there, and it helped - http://www.directadmin.com/forum/showthread.php?t=44449&page=1