Imagick is unable to open DNG images - php

As you can see, the image _IGP4559.DNG exists but Imagick can't open it.
JPEG images works just fine.
readImage() returns the same error.
Here is the image: http://files.patrikelfstrom.se/_IGP4559.DNG
I run this in the terminal to rule out all other variables.
$ ll /var/www/_IGP4559.DNG
-rw-rw-rw- 1 monsun monsun 11841201 May 17 03:37 /var/www/_IGP4559.DNG
$ php -a
Interactive mode enabled
php > new Imagick('/var/www/_IGP4559.DNG');
PHP Warning: Uncaught exception 'ImagickException' with message 'unable to open image `/tmp/magick-29917oe6CM9MIkN8A.ppm': No such file or directory # error/blob.c/OpenBlob/2709' in php shell code:1
Stack trace:
#0 php shell code(1): Imagick->__construct('/var/www/_IGP45...')
#1 {main}
thrown in php shell code on line 1

ImageMagick uses other programs to read some image formats, including DNG.
What is likely happening is that the program that ImageMagick expects to be able to use to read the DNG either isn't present on your system or isn't working correctly.
The file that lists these other programs is called delegates.xml
On my system the entry for DNG decoding is:
<delegate decode="dng:decode" command=""ufraw-batch" --silent --create-id=also --out-type=png --out-depth=16 "--output=%u.png" "%i""/>
i.e. it's trying to use the program 'ufraw-batch' to do the decoding, and like you're seeing it fails, as that program isn't usable on my system.
To solve this, you either need to install ufraw, or install a similar package that can convert files from the DNG format to a standard one that ImageMagick can read directly.

Related

/usr/bin/less: unrecognized option: X laravel docker error

i am using laravel on docker . i run my project when i exec into container and use
php artisan tinker
no matter what command i run i receive this error :
bash-5.1$ php artisan tinker
Psy Shell v0.11.8 (PHP 8.0.14 — cli) by Justin Hileman
>>> App\Models\User::where('id',12)->first()->createToken('testToken');
/usr/bin/less: unrecognized option: X
BusyBox v1.34.1 (2021-11-23 00:57:35 UTC) multi-call binary.
Usage: less [-EFIMmNSRh~] [FILE]...
View FILE (or stdin) one screenful at a time
-E Quit once the end of a file is reached
-F Quit if entire file fits on first screen
-I Ignore case in all searches
-M,-m Display status line with line numbers
and percentage through the file
-N Prefix line number to each line
-S Truncate long lines
-R Remove color escape codes in input
-~ Suppress ~s displayed past EOF
RuntimeException with message 'Error closing output stream'
any idea what can be wrong here ?
Busybox contains cutdown versions of many Unix/Linux utilities, including less. Either remove it and install the less package, as well as the other utilities it mimics, or hack artisan and remove the -X switch against /usr/bin/less. All the -X switch does is sort alphabetically by entry extension
Ugh just spent a ton of time messing with this one myself.
The root cause of this issue is the upgrading of the psypsh shell package that tinker users.
You can see in the release notes here https://github.com/bobthecow/psysh/releases/tag/v0.11.3
There are a few ways around this, as mentioned above, you can just install the less package using apk or apt-get.
You can also set the cli.pager property in your php.ini file to explicitly call less without the -X switch.
More info here: https://github.com/bobthecow/psysh/issues/717

Imagemagick : PHP Script giving 'import: unable to open X server'

I am trying to capture my current window using ImageMagick using PHP script, but got error as response. I did searched for it in stackoverflow, but none of them solved my issue. I did installed imagemagick in my machine Ubuntu 14.04 . Following command gives me proper output.
import -window root screenshot.jpg
I have this in image.php
<?php
exec( "/usr/bin/convert rose: -resize 200x200 output.jpg");
exec( "/usr/bin/import -window root screenshot.jpg");
?>
<img src="output.jpg"/>
I have executed this from terminal
php image.php
And i got desired response(screen got captured and a file got created name screenshot.jpg)
Then i tried to access this above php script using my browser, The convert command works fine but for import comamnd nothing happens, i tried checking my apache log and it gives me following error
import: unable to open X server `' # error/import.c/ImportImageCommand/368.
What am i missing here?
Is it a permission issue?
If you are trying to do this only for tests and/or studies:
1 - Check if the apache user can run the commands
/usr/bin/convert rose: -resize 200x200 output.jpg
/usr/bin/import -window root screenshot.jpg
2 - Check if you have X11 installed and configured, set the display env var. DISPLAY=:0 for example
3 - Adjust the command import
/usr/bin/import -window root
to /usr/bin/import -window apache_user
or /usr/bin/import -window your_user
If you are trying to create a website that will be accessed by multiple clients with different operational systems, your code will not work. You will need to do that using only PHP code because, obviously, the windows machine does not have the convert and the import commands.
You can read here some how to's

Image Processing (OpenCV with PHP) - Issue with the exec command

I have setup OpenCV 3.0 with python3.4 binding on ubuntu 14.04. I run OpenCV using virtualenv. So, everytime I have to run the workon cv command.
Now I want to run a python script that uses OpenCV library from PHP using the exec command.
exec("workon cv");
exec("python3 hough_circles.py")
This is the error :
sh: 1: workon: not found
Traceback (most recent call last):
File "hough_circles.py", line 1, in <module>
import cv2
ImportError: No module named 'cv2'
Two issues...
1. PATH to workon
The error message is telling you it doesn't know where workon is, so you better tell it the full path to where it is so exec() can find it, e.g.:
exec("/usr/local/bin/workon cv");
The /usr/local/bin above is just an example, if you want to know where it is on your system, run:
which workon
and use the output.
2. Subprocesses are independent
Even when you have got that set correctly, the process that executes workon then exits and you start a fresh, shiny new one - in which you have not run workon. So, you better do both things in the same process like this:
exec("/usr/local/bin/workon cv && /path/to/python3 hough_circles.py");

How to find path of user's home directory in PHP Cli on linux?

I am trying to write an script to check a particular directory exits or not on current logged in user's home directory via PHP.
when on terminal I use
cd ~
pwd
It shows /home/ramratan.
But when I tried via PHP the same thing like below
chdir("~");
PHP Warning: chdir(): No such file or directory (errno 2)
in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. chdir() php shell code:1
I also tried below
chdir("/home");
echo shell_exec("pwd");
It displays /home not /home/ramratan, if someone help me what should I do in chdir("/home") so that it returns /home/ramratan.
I have also tried below but no success
chdir("/home/".shell_exec("whoami"));
PHP Warning: chdir(): No such file or directory (errno 2)
in php shell code on line 1
PHP Stack trace:
PHP 1. {main}() php shell code:0
PHP 2. chdir() php shell code:1
The CLI version of PHP puts the environment variables in $_SERVER[]. The home directory of the current user can be found in $_SERVER['HOME']. There is no need to change any directory or run any external command.
Tested it on OSX and Ubuntu but I am confident it works on any Linux distribution. Cannot tell anything about Windows at the moment.
You can find the current username by using whomai as you already wrote. Use that name to find the line corresponding to that user in /etc/passwd. From that line cut out the home dir information:
$currentUserHomeDir = exec('grep `whoami` /etc/passwd | cut -d ":" -f6');

What is the difference between running a script from the command line and from exec() with PHP?

I'm trying to run a Python script using exec() from within PHP. My command works fine when I run it directly using a cmd window, but it produces an error when I run it from exec() in PHP.
My Python script uses NTLK to find proper nouns. Example command:
"C:\Python25\python.exe" "C:\wamp\projects\python\trunk\tests\find_proper_nouns.py" "I went to London this morning"
returns [London] when I run it from cmd, but throws an error in the Apache log when I run the same command from exec().The script is defintely getting run OK - if I change the python script to be print "Hello World" that is returned fine.
I know it's a big ask for anyone to know how to fix this NLTK error, but I could really do with any pointers as to why running it from exec is different to cmd. (The command is identical).
I'm running WAMP on Windows 7 with Apache 2.2.11.
Here's the error in the Apache log:
Traceback (most recent call last):
File "C:\wamp\projects\python\trunk\tests\find_proper_nouns_command_line.py", line 6, in <module>
parts = nltk.pos_tag(text)
File "C:\Python25\lib\site-packages\nltk\tag\__init__.py", line 62, in pos_tag
tagger = nltk.data.load(_POS_TAGGER)
File "C:\Python25\lib\site-packages\nltk\data.py", line 590, in load
resource_val = pickle.load(_open(resource_url))
File "C:\Python25\lib\site-packages\nltk\data.py", line 669, in _open
return find(path).open()
File "C:\Python25\lib\site-packages\nltk\data.py", line 451, in find
raise LookupError(resource_not_found)
LookupError:
**********************************************************************
Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not
found. Please use the NLTK Downloader to obtain the resource:
>>> nltk.download().
Searched in:
- 'C:\\nltk_data'
- 'D:\\nltk_data'
- 'E:\\nltk_data'
- 'C:\\Python25\\nltk_data'
- 'C:\\Python25\\lib\\nltk_data'
- 'C:\\Windows\\system32\\config\\systemprofile\\AppData\\Roaming\\nltk_data'
**********************************************************************
You have to run nltk.download() and choose 'maxent_treebank_pos_tagger'. You must make a python script and in it put:
#!/usr/bin/python
import nltk
nltk.download('maxent_treebank_pos_tagger');
then run it from command line. It will install the data files for the POS tagges, which you don't have installed yet.
After you do this it should work.
Your web server likely runs with other privileges than yourself. Possible problems include:
Path/file permission: can the web server user access the files it needs?
Different environment: are all necessary environment variables (PATH, Python-specific stuff, …) set?
Configuration: are there per-user configurations for Python or the module?
Tip: execute set in both the command prompt and from the PHP process and check the differences.
From the shell/terminal, you can use:
sudo python -m nltk.downloader maxent_treebank_pos_tagger
It will install maxent_treebank_pos_tagger (i.e. the standard treebank POS tagger in NLTK).

Categories