I want to run gmic with php


(takeshi yabuki) #1

Hello,

I am trying to run gmic with php exec

Server environment
ubuntu 16
php 5.6
gmic 1.7.9

result.php

<?php
$file = 'test.jpg';
 $savefile = 'complate.jpg';
putenv("GMIC_PATH=/xxxxx/xxxxx/gmic");
$command = 'gmic '.$file.' -gcd_hsl 1,0,0,180,0.2,0,1,1,0 -o '.$savefile;

if($re = exec($command,$res) === false) {
              $this->LastError = $command;
                 return false;
      }

cli php result.php ($re = 0) --> ok
apache ($re = 255) --> ng

It does not work properly


(Pat David) #2

Are there permissions issues for the apache service to the directory you are trying to write to? (I’m assuming this php file will run as the apache service - if not, check the permissions for the account that is running it).


(takeshi yabuki) #3

Thank you for answering

I tryed debug mode

[0] => 
[1] => [gmic] Unable to create resources directory 'gmicrc'.
[2] => [gmic]-0./ Start G'MIC interpreter (in debug mode).

putenv(“GMIC_PATH=/xxxxx/xxxxx/gmic”);

Is not this way of writing reflected?


(Pat David) #4

I’m honestly not sure, but will defer to someone smarter than me. :slight_smile:

If it works by running it from the terminal, I’m not sure what’s going on from apache. It still looks like permissions issues, but not sure how gimprc gets created in that context.


#5

paste stderr


(takeshi yabuki) #6
[1] => [gmic] Unable to create resources directory 'gmicrc'.
[2] => [gmic]-0./ Start G'MIC interpreter (in debug mode).
[3] => e[0;32;59m<gmic>-0./ Initial command line: '-cli_start -debug /var/www/dev-image/data/temp_image/6548462496084_2.jpg -gcd_hsl 1,0,0,180,0.2,0,1,1,0 -o /var/www/dev-image/data/temp_image/6548462496084_3.jpg'.e[0;0;0m
[4] => e[0;32;59m<gmic>./ Decompose command line into 7 items: e[0;0;0m
[5] => e[0;32;59m<gmic>./   item[0] = '-cli_start'e[0;0;0m
[6] => e[0;32;59m<gmic>./   item[1] = '-debug'e[0;0;0m
[7] => e[0;32;59m<gmic>./   item[2] = '/var/www/dev-image/data/temp_image/6548462496084_2.jpg'e[0;0;0m
[8] => e[0;32;59m<gmic>./   item[3] = '-gcd_hsl'e[0;0;0m
[9] => e[0;32;59m<gmic>./   item[4] = '1,0,0,180,0.2,0,1,1,0'e[0;0;0m
[10] => e[0;32;59m<gmic>./   item[5] = '-o'e[0;0;0m
[11] => e[0;32;59m<gmic>./   item[6] = '/var/www/dev-image/data/temp_image/6548462496084_3.jpg'e[0;0;0m
[12] => 
[13] => e[0;32;59m<gmic>-0./ e[1mEnter scope './'.e[0;0;0me[0;0;0m
[14] => e[0;32;59m<gmic>-0./ Item '-cli_start', selection [].e[0;0;0m
[15] => e[0;32;59m<gmic>-0./ Found custom command 'cli_start: ' (takes no arguments).e[0;0;0m
[16] => e[0;32;59m<gmic>-0./ Expand command line for command 'cli_start' to: ''.e[0;0;0m
[17] => e[0;32;59m<gmic>-0./cli_start/ Return from empty function 'cli_start/'.e[0;0;0m
[18] => e[0;32;59m<gmic>-0./ Item '-debug', selection [].e[0;0;0m
[19] => e[0;32;59m<gmic>-0./ Item '/var/www/dev-image/data/temp_image/6548462496084_2.jpg', selection [].e[0;0;0m
[20] => e[0;32;59m<gmic>-0./ Command '-input': arguments = '/var/www/dev-image/data/temp_image/6548462496084_2.jpg'.e[0;0;0m
[21] => [gmic]-0./ Input file '/var/www/dev-image/data/temp_image/6548462496084_2.jpg' at position 0 (1 image 1417x1062x1x3).
[22] => e[0;32;59m<gmic>-1./ Item '-gcd_hsl', selection [0].e[0;0;0m
[23] => e[0;32;59m<gmic>-1./ Command '-input': arguments = '-gcd_hsl'.e[0;0;0m
[24] => [gmic]-1./ Input file '-gcd_hsl' at position 1
[25] => [gmic]-1./ e[0;31;59me[1m*** Error *** Unknown command or filename '-gcd_hsl' (did you mean '-_ac_hsl' ?).e[0;0;0m
[26] =>

#7
...
$command = 'sudo -u $USER gmic ...

$USER is your user (no root) and the php has q have permission to run this


(David Tschumperlé) #8

Maybe some hints:
The G’MIC command -gcd_hsl requested here is not a part of the stdlib, but comes with the update file.
When not present , the update file is automatically downloaded into a resource folder (which is actually not named gmicrc/, but gmic/), located at $HOME/.config/gmic/.
If the resource directory cannot be created (which is apparently the case here), because of wrong rights for instance, the update file cannot be retrieved, and this particular filter won’t be available.
Two solutions then:

  • Either you allow G’MIC to create his resource directory (recommended).
  • Or, you download the update file (for instance the latest one here : http://gmic.eu/update203.gmic), and you invoke G’MIC with an explicit inclusion of this update file : gmic update203.gmic ... -gcd_hsl ...

(takeshi yabuki) #9

thank you everyone
I will try it at a later date.

 gmic /home/dev-image/gmic/update179.gmic ... -gcd_hsl ...

(darix) #10

oh man i I really hope neither of those params are user controlled. :wink:


(takeshi yabuki) #11

Mr. David Tschumperlé

It worked correctly in the way you say
I am grateful to you very much.

gmic /home/dev-image/gmic/update179.gmic ... -gcd_hsl ...

result

 [0] => [gmic]-0./ Start G'MIC interpreter (in debug mode).
    [1] => e[0;32;59m<gmic>-0./ Initial command line: '-cli_start -debug /home/dev-posukuma/gmic/update179.gmic /var/www/dev-image/data/temp_image/6550398110468_2.jpg -gcd_hsl 1,0,0,180,0.2,0,1,1,0 -o /var/www/dev-image/data/temp_image/6550398110468_3.jpg'.e[0;0;0m
    [2] => e[0;32;59m<gmic>./ Decompose command line into 8 items: e[0;0;0m
    [3] => e[0;32;59m<gmic>./   item[0] = '-cli_start'e[0;0;0m
    [4] => e[0;32;59m<gmic>./   item[1] = '-debug'e[0;0;0m
    [5] => e[0;32;59m<gmic>./   item[2] = '/home/dev-image/gmic/update179.gmic'e[0;0;0m
    [6] => e[0;32;59m<gmic>./   item[3] = '/var/www/dev-image/data/temp_image/6550398110468_2.jpg'e[0;0;0m
    [7] => e[0;32;59m<gmic>./   item[4] = '-gcd_hsl'e[0;0;0m
    [8] => e[0;32;59m<gmic>./   item[5] = '1,0,0,180,0.2,0,1,1,0'e[0;0;0m
    [9] => e[0;32;59m<gmic>./   item[6] = '-o'e[0;0;0m
    [10] => e[0;32;59m<gmic>./   item[7] = '/var/www/dev-image/data/temp_image/6550398110468_3.jpg'e[0;0;0m

(David Tschumperlé) #12

Good to know! I still don’t know why the G’MIC interpreter is running in debug mode, but you have probably the answer to this question :slight_smile: