Resizing raw images with PHP Imagick isn't working - image-processing

After multiple attempts, I was able to install ImageMagick and PHP Imagick extension. However, it fails to create Imagick object itself. Unfortunately, no error/ exception is shown anywhere.
My development environment is -
Apache/2.4.23 (Win64) PHP/7.0.10
CodeIgniter 3.0.3
imagick 3.4.3 (compiled with ImageMagick 6.9.3-7 Q16 x64 2016-03-27)
ImageMagick-7.0.8-61-Q16-x64-dll.exe
MAGICK_HOME and PATH variables are set correctly
magick and convert commands on command line are working fine.
The output of below test is Yes
<?php
echo extension_loaded('imagick') && class_exists('Imagick') ? 'Yes' : 'No', PHP_EOL;
The output of below test is resulting in ERR_CONNECTION_RESET
try {
$im = new Imagick('c:/IMG_2935.jpg'); OR
$im = new Imagick('c:/IMG_2935.cr2'); OR
$im = new Imagick();
$im->readImage('C:/e35455e32c684bc70d187418d95b9eb7.CR2');
} catch (ImagickException $e) {
print_r($e, true);
}
Pls help..
TIA

Related

textclips in moviepy on google colab (imagemagick error)

I'm trying to add text to a moviepy video, but I'm having trouble getting imagemagick to work on google colab.
The code:
!apt install imagemagick
from moviepy.editor import TextClip
txtClip = TextClip('Cool effect',color='white',
font="Amiri-Bold", kerning = 5, fontsize=100)
The error:
OSError: MoviePy Error: creation of None failed because
of the following error:
[Errno 2] No such file or directory: 'unset': 'unset'.
.This error can be due to the fact that ImageMagick is
not installed on your computer, or (for Windows users)
that you didn't specify the path to the ImageMagick
binary in file conf.py, or that the path you specified
is incorrect
research:
Not able to add Text Clip in Moviepy. Getting error related to Imagemagic
Getting error about ImageMagick With Python/MoviePy when I try add text clip
Attempt at resolving the issue:
Based on the error message, I started looking for the conf.py file. I ran
!find / -type d -name "conf.py" but none of the files returned seemed to be under the subdirectory of imagemagick.
I also modified the policy.xml file under /etc/ImageMagick-6 by commenting out the line <!--<policy domain="path" rights="none" pattern="#*"/>--> but to no avail seemingly.
Any ideas??
I had the same issue. Check if this work for you: Install with:
!apt install
imagemagick
Then to fix the issue that it thinks ImageMagick is not installed use this:
!cat /etc/ImageMagick-6/policy.xml | sed 's/none/read,write/g'>
/etc/ImageMagick-6/policy.xml

How to pass on path of ZLIB to ImageMagick?

Executing, both:
a)$/home/julia/displayImage.jl
b) julia> /home/julia/displayImage.jl
throw error:
...could not load library ...deps/usr/lib/libMagickWand-6.Q16.so" lib64/libz.so.1: version ZLIB_1.2.9,
where displayImage.jl, is:
#! /opt/julia-1.1.0/bin/julia
using Images, TestImages, FileIO, Colors, ImageView;
function displayImage(path::String)
img = nothing;
if isfile(path)
img = load(path);
imshow(img);
else
info("ERROR: While loading image!");
end
end
the same code works when each command is copied, pasted and executed at julia prompt during the ImageMagick's build session but not after exit from the session!
It is observed that: a)julia is not using the ZLIB installed in its deps folder after build session of ImageMagick. b)the os and julia packages CodecZlib, Conda, ZipFile, ImageMagick... have different versions of ZLIB.
Please advise me on a) how to pass on ZLIB path which is inside the folder of package, ImageMagick while executing at shell prompt and b) also using single updated version!
Executing the followong line at shell prompt resolves the issue for the session.
$export LD_LIBRARY=/opt/julia/julia-1.1.0/share/julia/stdlib/v1.1/ImageMagick/deps/usr/lib:/usr/lib64:$LD_LIBRARY_PATH
where the first path is of ZLIB inside ImageMagick package.

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.

how to convert Pdf to image via imagemagick command?

I am using following environment:
Ubunut : 11.0 (virtual machine)
Imagemagick : ImageMagick-6.9.3-7
I have execut following command:
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar xzvf ImageMagick.tar.gz
ls
cd ImageMagick<version number here>/
./configure
make clean
make
sudo make install
ldconfig /usr/local/lib
After executing below command:
make check
40 test case 39 pass only 1 is fail (FAIL: tests/wandtest.tap 1)
Now i want to convert pdf file to jpg via command:
convert test.pdf test.jpg
convert: no decode delegate for this image format PNG' # error/constitute.c/ReadImage/501.
convert: no images definedtest.jpg' # error/convert.c/ConvertImageCommand/3252
convert test.pdf test.png
convert: no decode delegate for this image format PNG' # error/constitute.c/ReadImage/501.
convert: no images definedtest.png' # error/convert.c/ConvertImageCommand/3252.
anyone can suggest me how can i do ?
ImageMagick uses assorted external libraries to do its dirty work as far as input and output handling goes for various formats. In your case:
For reading PDFs, you need to have Ghostscript installed. Also it needs to be in your path as gs in order to work, so don't use that for some other shell alias. For more details see: https://superuser.com/q/819277/33767
For writing PNGs you'll need libpng.
Once those things are on your system (and in the case you compiled IM yourself, on your system at the time of compile) you should be golden.
It may be that the issue is not with the writing but with the reading of the PDF itself.
Check the ImageMagick policy.xml.
sudo nano /etc/ImageMagick-6/policy.xml
Find the PDF and change to this:
<policy domain="coder" rights="read|write" pattern="PDF" />
This solved for me.
Same problem. Solved it with:
apt-get -y install ghostscript

Windows commands in ruby

How do I run a Windows command in an Ruby app?
I am trying to run something like:
output = `cd #{RAILS_ROOT}/lib && java HelloWorld #{param1} #{param2}`
I print the result of the line above and paste it to a command prompt in Windows and it works just fine. However, when i run app and hit this code, output is blank rather than have a string I get back from HellowWorld. In HelloWorld I do a System.out.print("helloworld")
The following:
output = `cmd.exe /C dir`
puts "OUTPUT #{output}"
Returns:
OUTPUT
Issue in JRuby 1.5.3 fixed in JRuby 1.5.5:
http://www.jruby.org/2010/11/10/jruby-1-5-5.html
Try to use File#join here. It will generate crossplatform path for you
http://apidock.com/ruby/File/join/class
my_path = File.join(RAILS_ROOT, "lib")
output = `cd #{my_path} && java HelloWorld #{param1} #{param2}`
Also you can execute your system commands this way:
`cd #{my_path} && java HelloWorld #{param1} #{param2}`
system("cd #{my_path} && java HelloWorld #{param1} #{param2}")
%x[cd #{my_path} && java HelloWorld #{param1} #{param2}]
Related topic: System call from Ruby
Backticks work fine for me. Try:
output = `dir`
to prove to yourself that it's working. At that point, your question is how to run a Java app from the command line, or why your particular app isn't work. Note that you can temporarily change the working directory like this:
Dir.chdir(File.join(RAILS_ROOT,'lib')) do
output = `...`
end

Resources