Fatal error: Uncaught Error: Call to undefined method Imagick::flattenImages() - imagemagick

I have been using Imagick and ImageMagick in one of my Image processing scripts. It is working perfectly on my development server has the following configurations.
PHP Version 7.0.33
Imagick 3.4.3
ImageMagick 6.7.9-10 2016-05-05 Q16 http://www.imagemagick.org
But on my client's server, I am getting the following error.
Fatal error: Uncaught Error: Call to undefined method Imagick::flattenImages()
My client has the following configuration
PHP Version 7.2.15
Imagick 3.4.3
ImageMagick 7.0.7-11 Q16 x86_64 2017-11-20 http://www.imagemagick.org
I just wonder how the Imagick::flattenImages() is missing from my client's server as both my server and client's server has the same Imagick version

Try this:
$image = new Imagick();
$image->readImage( $path_to_file );
$flattenedImage = $img->mergeImageLayers( imagick::LAYERMETHOD_FLATTEN );
PHP docs for Imagick::mergeImageLayers() method
You can also pass one of these constants as a layer method:
imagick::LAYERMETHOD_UNDEFINED (ImageMagick 6.2.9+)
imagick::LAYERMETHOD_COALESCE (ImageMagick 6.2.9+)
imagick::LAYERMETHOD_COMPAREANY (ImageMagick 6.2.9+)
imagick::LAYERMETHOD_COMPARECLEAR (ImageMagick 6.2.9+)
imagick::LAYERMETHOD_COMPAREOVERLAY (ImageMagick 6.2.9+)
imagick::LAYERMETHOD_DISPOSE (ImageMagick 6.2.9+)
imagick::LAYERMETHOD_OPTIMIZE (ImageMagick 6.2.9+)
imagick::LAYERMETHOD_OPTIMIZEPLUS (ImageMagick 6.2.9+)
imagick::LAYERMETHOD_OPTIMIZEIMAGE (ImageMagick 6.3.0+)
imagick::LAYERMETHOD_OPTIMIZETRANS (ImageMagick 6.3.0+)
imagick::LAYERMETHOD_REMOVEDUPS (ImageMagick 6.3.0+)
imagick::LAYERMETHOD_REMOVEZERO (ImageMagick 6.3.0+)
imagick::LAYERMETHOD_COMPOSITE (ImageMagick 6.3.0+)
imagick::LAYERMETHOD_MERGE (ImageMagick 6.3.7+)
imagick::LAYERMETHOD_FLATTEN (ImageMagick 6.3.7+)
imagick::LAYERMETHOD_MOSAIC (ImageMagick 6.3.7+)

Related

Exception in GraalVM 22.2 native-image on Ubuntu 22.04

I am trying to compile a Java app into a native image using GraalVM 22.2 on my Ubuntu 22.04 workstation. I have followed the installation instructions here:
https://www.graalvm.org/22.1/docs/getting-started/linux/
GraalVM is installed and seems happy:
# /opt/graalvm/bin/java -version
openjdk version "17.0.4" 2022-07-19
OpenJDK Runtime Environment GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06)
OpenJDK 64-Bit Server VM GraalVM CE 22.2.0 (build 17.0.4+8-jvmci-22.2-b06, mixed mode, sharing)
Here's how I'm calling native-image for my app:
/opt/graalvm/bin/native-image \
-H:ReflectionConfigurationFiles=graalvm/reflect.json \
-H:+ReportExceptionStackTraces \
--no-fallback \
--enable-url-protocols=http \
--initialize-at-build-time=org.slf4j.LoggerFactory \
--initialize-at-build-time=org.slf4j.impl.SimpleLogger \
--initialize-at-build-time=org.slf4j.impl.StaticLoggerBinder \
-jar ../app/target/app-0.9.jar
But I'm getting this exception:
Error: Collecting native-compiler info with '/usr/bin/gcc -v' failed
Error: To prevent native-toolchain checking provide command-line option -H:-CheckToolchain
com.oracle.svm.core.util.UserError$UserException: Collecting native-compiler info with '/usr/bin/gcc -v' failed
To prevent native-toolchain checking provide command-line option -H:-CheckToolchain
at org.graalvm.nativeimage.builder/com.oracle.svm.core.util.UserError.abort(UserError.java:138)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.c.codegen.CCompilerInvoker.addSkipCheckingInfo(CCompilerInvoker.java:104)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.c.codegen.CCompilerInvoker.<init>(CCompilerInvoker.java:72)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.c.codegen.CCompilerInvoker$LinuxCCompilerInvoker.<init>(CCompilerInvoker.java:212)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.c.codegen.CCompilerInvoker.create(CCompilerInvoker.java:80)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.setupNativeImage(NativeImageGenerator.java:891)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:561)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:521)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:407)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:585)
at org.graalvm.nativeimage.builder/com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:128)
However, gcc is installed and is also happy:
# /usr/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-gBFGDP/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-gBFGDP/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (Ubuntu 11.2.0-19ubuntu1)
It turns out that the problem was that some permissions got clobbered in the /opt/graalvm folder. Removing and re-extracting the folder fixed the problem for me.

"gs: symbol lookup error: /lib64/libgs.so.9: undefined symbol: FT_Property_Set" Error when converting .ai file to .png with ghostscript 9.25

I'm using ImageMagick with ghostscript 9.25 to convert images. When I try to convert .ai file to .png with image magic I'm getting the below error in command line
My command ./convert /home/sample_ai_file2.ai /home/ai_out.png
gs: /opt/software/alfresco-one/common/lib/libtiff.so.5: no version information available (required by /lib64/libgs.so.9)
gs: /opt/software/alfresco-one/common/lib/libjpeg.so.62: no version information available (required by /lib64/libgs.so.9)
gs: symbol lookup error: /lib64/libgs.so.9: undefined symbol: FT_Property_Set
.convert.bin: NoImagesForWrite '-write' '/home/sshtest/ai_out.png' at CLI arg 2 # error/operation.c/CLINoImageOperator/4769.
.convert.bin: NoImageForProperty "%w" # warning/property.c/GetMagickPropertyLetter/2561.
.convert.bin: UnknownImageProperty "%w" # warning/property.c/InterpretImageProperties/3499.
.convert.bin: NoImageForProperty "%h" # warning/property.c/GetMagickPropertyLetter/2449.
.convert.bin: UnknownImageProperty "%h" # warning/property.c/InterpretImageProperties/3499.
.convert.bin: NoImageForProperty "%m" # warning/property.c/GetMagickPropertyLetter/2480.
.convert.bin: UnknownImageProperty "%m" # warning/property.c/InterpretImageProperties/3499.
Does any one know the reason for this error ? I can convert all the other image types without any issue.
I was able to find the cause for the above mentioned issue. The error was due to having two versions of GS installed in my system.
When I install ImageMagick, GS 8.64 is also automatically installed by default, then I have again manually installed GS 9.25.
Removing the GS 9.25 resolved my issue.

failed to execute command 'gs' when converting a single page of pdf to jpg in imagemagick

When I am executing the below command (to create thumbnail of a pdf file)
convert -density 300 'image.pdf' -colorspace RGB -resize '100x100^' -gravity north -extent 100x100 'image_thumbnail.jpg
I am getting the below error
convert: FailedToExecuteCommand `'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' -dFirstPage=1 -dLastPage=1 '-sOutputFile=/tmp/magick-2243905865hWInyt6%d' '-f/tmp/magick-22439X8ArwDDJggvw' '-f/tmp/magick-22439Omw2cAWv3jxW'' (-1) # error/delegate.c/ExternalDelegateCommand/478.
Hi Prashant.
I had such an issue using node-pdf-image package. I had been investigating it for several days before I found the solution.
I tried to update the versions of ImageMagick and GhostScript, but it didn't help.
The only workaround I found was the next one: use GraphicsMagick and invoke the convert prefixed with gm - like gm convert [options].
But of course, this solution was acceptable for my stuff, and it depends on the task.

How to keep Tesseract from inserting extra whitespace in words?

I asked about this on the Tesseract forum already
Via Tesseract (and ImageMagick), I'm trying to find out the text of this
PDF file
This is the section of the PDF that I'm working on, it's line #7 of the
PDF:
In this section, Tesseract is running into problems when trying to identify
the string CONSTRUCTORA.
It sees CO NSTRUCTO RA
It should see CONSTRUCTORA
Can anyone suggest any possible fixes for this?
This is the commandline sequence:
convert -density 600 my_pdf.pdf tmp.tif
tesseract -l spa tmp.tif stdout > tmp.txt
These are the software versions:
~% tesseract --version
tesseract 3.05.01
leptonica-1.74.4
libgif 4.1.6(?) : libjpeg 8d (libjpeg-turbo 1.3.0) : libpng 1.2.50 :
libtiff 4.0.3 : zlib 1.2.8
~% convert --version
Version: ImageMagick 6.7.7-10 2014-08-28 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP
For dealing with the irregular kerning of the PDF file, Will suggested tweaking the parameters around tosp_min_sane_kn_sp of the docs https://github.com/naptha/tesseract.js/blob/master/docs/tesseract_parameters.md
Setting tosp_min_sane_kn_sp=2.8 solved the issue that was described in the question.
The new Tesseract invocation is the following:
tesseract -c tosp_min_sane_kn_sp=2.8 -l spa tmp.tif stdout > tmp.txt
The default value for tosp_min_sane_kn_sp seems to be 1.5. So far, I have only tested with values larger than 1.5.

ImageMagick no encode delegate

I used to be able to convert text to an image using ImageMagick but now I get this error message:
$ echo text | convert -background none text:- file
convert: no encode delegate for this image format `TEXT' # error/constitute.c/WriteImage/1167.
ImageMagick was installed using Homebrew
imagemagick: stable 7.0.7-10 (bottled), HEAD
Tools and libraries to manipulate images in many formats
https://www.imagemagick.org/
/usr/local/Cellar/imagemagick/7.0.7-10 (1,523 files, 23.1MB) *
Poured from bottle on 2017-11-10 at 15:46:33
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/imagemagick.rb
In IM 7, convert is replaced by magick. You also have not specified an output image format for "file". Try this:
echo "text" | magick -background none text:- file.png
or
echo "text" | magick -background none text:- PNG32:file
That works for me on IM 7.0.7.10 Q16 Mac OSX
What do you get from
magick -version
Does it include freetype?
If not, then you probably need to install Freetype with ImageMagick via Homebrew

Resources