PHP 在执行 Octave 程序时无法输出图形

问题描述

我正在制作一个执行 Octave 程序的 PHP 脚本。 Octave 程序生成图形输出,使用 getframe() 将其拆分为 4 个不同的图像,并使用 imwrite() 保存它们。这是输出output.jpg。 和程序:

function map(M,longueurMorceau=12,nbSegments=30,fps=25) 
  pkg load image;
  M = load("mat.txt");
  #rendu graphique
  colormap("jet");#changement de la colormap
  m = pcolor(M);#affichage de la map
  c = colorbar;#affichage de la barre de couleur
  axis("ij");#inversion des axes
  shading interp;#active l'interpolation
  refresh;#force le rendu graphique
  set(c,"units","pixels");
  
  #mise \ufffd l'\ufffdchelle des axes
  xlabel("t(s)"); ylabel("d(mm)");#\ufffdtiquettes
  xtick = get(gca,"XTick");#\ufffdchelle de l'axe x
  ytick = get(gca,"YTick");#\ufffdchelle de l'axe y
  set(gca,"YTick",ytick,"YTickLabel",round((ytick*longueurMorceau)/nbSegments));#mm
  set(gca,"XTick",xtick,"XTickLabel",round(xtick/fps));#s
  
  #sauvegarde des \ufffdl\ufffdments sous diff\ufffdrents fichiers
  colorbar_position = get(c,"position"); marge = 40;
  #capture du rendu
  refresh;
  f = getframe(gcf,[colorbar_position(1),colorbar_position(2)-marge,colorbar_position(3)+marge,colorbar_position(4)+marge]);
  display(f);
  #sauvegarde du fichier colorbar.png
  imwrite(f.cdata,"colorbar.jpg");

  f = getframe(gca); 
  map = imresize(f.cdata,[colorbar_position(4) 390]);#image redimensionn\ufffde 
  imwrite(map,"map.jpg");#map
  
  set(gca,"Units","pixels");
  map_position = get(gca,"position");
  f = getframe(gcf,[map_position(1)-marge,map_position(2)-marge,marge-5,map_position(4)+marge]);
  y_axis = imresize(f.cdata,[colorbar_position(4)+marge marge]);
  imwrite(y_axis,"y.jpg");#axe Y
  
  f = getframe(gcf,[map_position(1),map_position(3)+marge,marge-2]);
  x_axis = imresize(f.cdata,[marge 390+marge]);
  imwrite(x_axis,"x.jpg");#axe X
    
endfunction

从命令行执行程序时,它起作用了,4个不同的图像存储在当前文件夹中。但是使用 PHP,事情变得复杂了...

这是执行 Octave 程序的 PHP 代码行:

 $command="sudo octave map.m";
        echo $command; 
        $out=shell_exec($command);

这是浏览器上的结果:

browser_result

现在我认出了数字,它们来自图形的轴,这意味着程序确实绘制了一些东西,但不是显示它,PHP 只是将它打印为原始文本。结果,getFrame 不包含图形数据,因此不会保存图像,因为 Octave 需要打开一个图形窗口才能创建不同的图片

会不会是权限问题?就像 PHP 没有打开图形窗口的权利? 我真的不知道如何解决这个问题。任何帮助将不胜感激:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)