0

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?

MONISH
  • 1
  • 2

1 Answers1

0

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

Joao Vitorino
  • 2,976
  • 3
  • 26
  • 55