I am able to do use the ImageMagick convert function on the command line with no problems:
/usr/local/magick/bin/convert a.pdf b.png
I then put it in a one-line PHP file named testconvert.php:
system("/usr/local/magick/bin/convert a.pdf b.png", $code);
and it works fine as a command line call from PHP:
php testconvert.php
But, when I run the script from my browser on localhost:
http://localhost/~me/testconvert.php
I get the error:
convert: no images defined `b.png' # error/convert.c/ConvertImageCommand/3253
I found a lot of folks who have encountered similar problems and fixes ranged from using the absolute path for the files (didn't help) to installing ghostscript (didn't help, either). I'm going a bit gaga with this. Would anyone have any thoughts about what I can possibly try?
Thanks!
Change your system() line to:
system("pwd");
and you will see which directory your script is running in.
Related
When I try using this Command: opencv_createsamples -img image.jpg -bg bg.txt -info /info/info.lst -pngoutput info -num 2600 it tells me: Invalid background description file.
I now tried:
./neg/1.jpg
./net/2.jpg
Didn't work.
./neg/1.jpg
./neg/2.jpg
Didn't work as well.
neg/1.jpg
neg/2.jpg
Same problem
neg/1.jpg
neg/2.jpg
Also not working.
Any ideas?? I really need help.
Thanks
FritzFurtz
I had the same problem and tried many different things (adding full path names in the bg.txt, convert to UTF-8,...) - which resulted in getting slightly different looking errors - but still, no success. I am following this tutorial - and I am preparing all the files on my windows laptop & then pushing them to a ubuntu server.
Then I read it might be caused by difference in line ending (CLRF and LF) and checked my file (on the ubuntu server):
$ file bg.txt
bg.txt: UTF-8 Unicode (with BOM) text, with CRLF line terminators
I converted the file from dos2unix:
$ sudo apt install dos2unix
$ dos2unix bg.txt
dos2unix: converting file bg.txt to Unix format ...
$ file bg.txt
bg.txt: ASCII text
And now the opencv_createsamples command worked.
I was experiencing the same problem and it was very frustrating. But now it's solved.
1) CTRL + A ; CTRL + C; on your background description file to copy all it's content.
2) Create a new background description file (e.g.: bg2.txt), and CTRL + V to paste all the content you copied. Save it.
3) Run your command again, using, of course, the new bg description file (-bg bg2.txt).
It worked for me and might work for you.
Cheers,
Geraldo Neto
I had the exact same problem. I tried changing the bg.txt encoding and it made no difference. I deleted all instances of OpenCV on my Ubuntu server and rebooted. I typed:
git clone https://github.com/Itseez/opencv.git
into the terminal.
Once downloaded, rebooted the server and proceeded with:
opencv_createsamples -img image.jpg -bg bg.txt -info /info/info.lst -pngoutput info -num 1500
That seemed to fix my "Invalid background description file" error.
Bear in mind that I tried to create a new folder and add a fresh download of OpenCV to use on a separate project and it just copied my existing file.
Delete all instances of the OpenCV folder before rebooting and redownloading it!
I had this problem too and I solved it by changing encoding of my bg.txt to UTF-8. Also, my file looks like:
neg/1.jpg
neg/2.jpg
On Linux (Ubuntu) adding one more empty line doe snot work. File was in utf-8 encoding. Resolved with converting from "linux" to "dos" line ending format.
I have successfully installed ImageMagick on my local Windows 7 PC. And test the convert C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg
But when I am trying to this from a PHP file named C:\xampp\htdocs\test\index.php
with the code
<?php
exec("C:\Program Files\ImageMagick-6.8.9-Q16\convert C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg", $output, $return);
?>
It does not work. The a.jpg file exists. and I am using the browser to run the index.php file with the path http://localhost/test/index.php
$output is blank and $return is 1.
However when I use
<?php
exec("C:\Program Files\ImageMagick-6.8.9-Q16\convert", $output, $return);
?>
I get the output as Imagemagick version...
The same output if I run the command "convert" in the command prompt.
I am using xamp in windows 7.
I have searched a lot, but the issues mentioned there is not which I face.
Because when I used only "convert" in PHP exec I got the output.
So could not understand what is the actual problem.
I've been banging my head against this issue for several hours now.
exec("C:\Program Files\ImageMagick-6.8.9-Q16\convert C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg", $output, $return);
This code should work fine, just one issue, try running "C:\Program Files\ImageMagick-6.8.9-Q16\convert C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg" without the quotes in a command prompt and you get 'C:\Program' is not recognized.
Need to quote the path to the convert exe.
Try this exec('"C:\Program Files\ImageMagick-6.8.9-Q16\convert" C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg', $output, $return);
It should work.
Cheers!
I know this question has already been answered but I was banging my head against a wall for 5 hours last night trying to do this.
I think it's worth noting that if any of your paths have spaces in them (the executable, input file and output file) then they need to each be quoted separately:
i.e.
exec('"C:\Program Files\ImageMagick-6.9.1-Q16\convert" "C:\Documents\Web Dev\test.jpg" -resize 50x50 "C:\Documents\Web Dev\output.jpg"', $output, $return);
I hope this helps to save 5 hours of someone else's life.
I just downloaded ImageMagick but am not sure if it's working. I typed in 'which convert' into my terminal and nothing happened. I also tried typing in 'convert logo: logo.gif' then 'identify logo.gif' and lastly 'display logo.gif' and nothing seemed to happen (these three commands were specified on Windows).
Then I tried following this video: http://www.youtube.com/watch?v=gEWAVlNCKhg
However, it still didn't work and on the last step of the video. I got the following error: ERROR: While executing gem ... (OptionParser::InvalidOption) invalid option: ----with-opt-include=C:/ImageMagick/SourceCode
Can anyone advise on how to correctly install imagemagick on windows or what these errors mean?
That video has a bunch of unnecessary stuff if all you want to do is get ImageMagick working as a standalone product on Windows. All you need to do is:
Download latest Windows binary from imagemagick.org. Right now, that file is located here.
Run the installer (leave all default values the way they are)
Open a command prompt (Start --> Run --> cmd.exe)
Navigate to the ImageMagick folder in the command prompt window. For the default install path, this is done as follows :
Change to the root directory of the C: drive (type cd\ followed by the enter key)
Change to the ImageMagick folder (type cd "Program Files\ImageMagick-6.8.6-Q16" followed by the enter key)
Test that it's working with the convert command: convert images\logo.jpg logo.gif
Look at the directory listing and check the for a logo.gif file with the current time/datestamp (dir logo.gif, followed by enter key).
Note: when you run the convert command, there will not be any output to the command prompt unless you turn on the verbose flag e.g. (convert -verbose images\logo.jpg logo.gif)
I noticed that in my installation that there was not a 'display.exe', but there was an 'imdisplay.exe". I tried using imdisplay in a folder that had images, and it did not how a window. I double clicked imdisplay.exe in the installation folder, and windows came up, including all of the ones I tried to open on the command line. When I closed all of those windows and tried the command line again, it worked.
I am not sure where you are getting 'which convert' (I did not watch the video). I can see all of the exe files that are available in the installation folder. convert.exe is one of them, so in a regular cmd window (I do not know anything about Powershell GitShell), you can just type:
convert logo.png logo.jpg
or something like that.
I'm getting the following error in my development.log
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: /tmp/stream28514-0 is not recognized by the 'identify' command.>
And i've googled about this error and i found out that many people have solved this by adding this line
Paperclip.options[:command_path] = "/usr/local/bin"
However, i still get the same error even after adding that line! I've tried everything possible!
Any help would be highly appreciated!
Regards,
Punit
The Paperclip.options[:command_path] setting is for the location of your ImageMagick executables (in this case identify). Try running which identify and setting the option to be the directory that is returned. If that command doesn't return anything, make sure that ImageMagick is properly installed.
Here is what worked for me...
I uninstalled the imagemagick that i installed from the official webpage.
I reinstalled it from sudo apt-get install imagemagick
then i did write Paperclip.options[:command_path] = "to/correct/path"
THE PROBLEM HERE WAS...
when i ran "which identify" it appearde that the path was "usr/local/bin/identify"
it means that we I was supposed to put as a path "usr/local/bin" as my path.
BUT IT DIDN'T WORKED!
I surprisingly found that i identify was also in the "usr/bin" path. So i changed:
"usr/local/bin" to "usr/bin"
And that was all!
It means that it cannot find ImageMagick's executable identify on the location you specified in Paperclip.options[:command_path] (in your case /usr/local/bin).
This is tipically caused by two reason:
It might be that you actually did not installed ImageMagick.
SOLUTION: install it:
For MAC: sudo port install ImageMagick (which installs the binary release)
For UBUNTU: sudo sudo apt-get install imagemagick
It might be that the location where you installed ImageMagick is not /usr/local/bin but something else.
SOLUTION: find where it is installed, or via the command:
which identify (in case that identify is in the current PATH, as it should be)
or via a raw find through the file system:
find / -name identify
Anyway, the usual location for those file in Ubuntu should be /usr/bin
There are two possible problems:
Image Magick is not installed or broken
Paperclip is not able to find Image Magick
Let's take them one at a time:
1. Check you have Image Magick installed and it is working
Type:
identify
at the command line, it should work. If it isn't found, or fails to work, install Image Magick. Did this fix it? If not, continue:
2. Help Paperclip find Image Magick
Type:
which identify
at the command line to get the path to the identify command. Now, in production.rb, add the following line to the configuration block:
Paperclip.options[:command_path] = "/usr/bin"
Restart your server. That should fix it.
usr/bin worked me (Fedora 14 core)
Try running the identify command in the command line and see if that gives you some error message. I found out that my server was missing some delegate libraries.
identify example.jpg
I'm getting the following error in my development.log
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: /tmp/stream28514-0 is not recognized by the 'identify' command.>
And i've googled about this error and i found out that many people have solved this by adding this line
Paperclip.options[:command_path] = "/usr/local/bin"
However, i still get the same error even after adding that line! I've tried everything possible!
Any help would be highly appreciated!
Regards,
Punit
The Paperclip.options[:command_path] setting is for the location of your ImageMagick executables (in this case identify). Try running which identify and setting the option to be the directory that is returned. If that command doesn't return anything, make sure that ImageMagick is properly installed.
Here is what worked for me...
I uninstalled the imagemagick that i installed from the official webpage.
I reinstalled it from sudo apt-get install imagemagick
then i did write Paperclip.options[:command_path] = "to/correct/path"
THE PROBLEM HERE WAS...
when i ran "which identify" it appearde that the path was "usr/local/bin/identify"
it means that we I was supposed to put as a path "usr/local/bin" as my path.
BUT IT DIDN'T WORKED!
I surprisingly found that i identify was also in the "usr/bin" path. So i changed:
"usr/local/bin" to "usr/bin"
And that was all!
It means that it cannot find ImageMagick's executable identify on the location you specified in Paperclip.options[:command_path] (in your case /usr/local/bin).
This is tipically caused by two reason:
It might be that you actually did not installed ImageMagick.
SOLUTION: install it:
For MAC: sudo port install ImageMagick (which installs the binary release)
For UBUNTU: sudo sudo apt-get install imagemagick
It might be that the location where you installed ImageMagick is not /usr/local/bin but something else.
SOLUTION: find where it is installed, or via the command:
which identify (in case that identify is in the current PATH, as it should be)
or via a raw find through the file system:
find / -name identify
Anyway, the usual location for those file in Ubuntu should be /usr/bin
There are two possible problems:
Image Magick is not installed or broken
Paperclip is not able to find Image Magick
Let's take them one at a time:
1. Check you have Image Magick installed and it is working
Type:
identify
at the command line, it should work. If it isn't found, or fails to work, install Image Magick. Did this fix it? If not, continue:
2. Help Paperclip find Image Magick
Type:
which identify
at the command line to get the path to the identify command. Now, in production.rb, add the following line to the configuration block:
Paperclip.options[:command_path] = "/usr/bin"
Restart your server. That should fix it.
usr/bin worked me (Fedora 14 core)
Try running the identify command in the command line and see if that gives you some error message. I found out that my server was missing some delegate libraries.
identify example.jpg