0

I have an application which was developed using php and I want to print a dithering image through my printer so what I am doing is I have an application called ImageMagick. In this application using command prompt I will pass an image path and the destination folder. So when I run the command in the command prompt it will convert the image and save it in destination folder.

Firstly I tried the php exec() for the below code

    <?php
     echo exec('ipconfig');
    ?>

The above code gives the output on the browser

When I give the below code:

   <?php
     echo exec('date');
   ?>

It gives the output as below

Enter the new date: (mm-dd-yy)

But When I run the date command on the command prompt it gives the current date

I tried to run the Imagemagick command in php code as shown below

<?php
echo exec('convert "C:\bhargav\dev\download.jpg" -resize 384 -dither FloydSteinberg -remap pattern:gray50 "C:\bhargav\dev\con.jpg"');
?>

But it doesn't save any image as output and no error is shown on the browser.

convert "C:\bhargav\dev\download.jpg" -resize 384 -dither FloydSteinberg -remap pattern:gray50 "C:\bhargav\dev\con.jpg"

when the above command is given in the command prompt it gives me the output.

Where am I going wrong?

  • I think it could be a lot of things. It could be file permissions. See this SO question: https://stackoverflow.com/questions/20072696/what-is-different-between-exec-shell-exec-system-and-passthru-functions for other options. You could also benefit from sending stderr to stdout so that you can see any errors that occur. – ajon Feb 07 '19 at 06:49
  • Have you checked for [safe mode](https://secure.php.net/manual/features.safe-mode.php)? [This](https://stackoverflow.com/questions/538939/php-exec-will-not-execute-shell-command-when-executed-via-browser) question also checks a lot of options why exec might not work. – Gerriet Feb 07 '19 at 07:01
  • Try shell_exec instead of echo exec – Bonzo Feb 07 '19 at 08:08
  • @Bonzo `shell_exec` works for date but not for image conversion –  Feb 07 '19 at 10:24
  • @Bonzo tried but not working –  Feb 08 '19 at 05:23

0 Answers0