1

I found a weird bug in python pyheif library. I am trying to run external python code in php function exec('python command', $output); I can get the python message in array with second argument $output from exec().

python code (test.py):

# -*- coding: utf-8 -*-
import sys
import os
import base64
from PIL import Image # pip3 install pillow
import pyheif  # pip3 install pyheif
import io
print("hello world!")

php code (test.php):

<?php
exec("python3 test.py", $output);
var_dump($output);

This is working well on command line but not on the web browser. But when I remove import hyheif line or move print('hello world') ahead of hyheif line, it works both cli and web browser. I get the result: hello world string.

I got no clue. Does hyheic library cause this problem on the web browser while it works fine on the command line?

I need to import hyheic library for converting heic to jpeg on the browser. My problem is I am not able to get the result on php from python code.

When I import hyheif library, I get the following result:

shell:/var/www/myfolder$ php test.php
array(1) {
  [0]=>
  string(12) "hello world!"
}

on my chrome browser:

array(0){}
user1942626
  • 805
  • 1
  • 9
  • 15
  • Possibly stupid question: is the computer where you have your command line success the same computer where you run your web server? (i.e. is pyheif installed on both the cli machine and the server machine)? – Pam Dec 08 '21 at 14:47
  • You'll want to start by capturing more information about that Python call, including the exit code **and stderr**: https://stackoverflow.com/a/57071648/476 – deceze Dec 08 '21 at 14:47
  • To expand on the above a bit: Python is probably not silently refusing to work, it *probably* has some issue importing that library, because the environment in which it is executed is somehow different. In this case it will output proper error messages which will help in diagnosing the issue. So **make sure you catch all the error output from calling that command!** – deceze Dec 08 '21 at 15:16

0 Answers0