PHP可以';执行倍频程程序时输出图

PHP可以';执行倍频程程序时输出图,php,image,graph,permissions,octave,Php,Image,Graph,Permissions,Octave,我正在制作一个执行八度音阶程序的php脚本。Octave程序生成图形输出,使用getframe()将其拆分为4个不同的图像,并使用imwrite()保存它们。以下是输出: . 该计划: function map(M,longueurMorceau=12,nbSegments=30,fps=25) pkg load image; M = load("mat.txt"); #rendu graphique colormap("jet");#c

我正在制作一个执行八度音阶程序的php脚本。Octave程序生成图形输出,使用
getframe()
将其拆分为4个不同的图像,并使用
imwrite()
保存它们。以下是输出: . 该计划:

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(2)-marge,map_position(3)+marge,marge-2]);
  x_axis = imresize(f.cdata,[marge 390+marge]);
  imwrite(x_axis,"x.jpg");#axe X
    
endfunction
 $command="sudo octave map.m";
        echo $command; 
        $out=shell_exec($command);
当从命令行执行程序时,它工作,并且4个不同的图像存储在当前文件夹中。但是使用php,事情会变得复杂

以下是php中执行倍频程程序的代码行:

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(2)-marge,map_position(3)+marge,marge-2]);
  x_axis = imresize(f.cdata,[marge 390+marge]);
  imwrite(x_axis,"x.jpg");#axe X
    
endfunction
 $command="sudo octave map.m";
        echo $command; 
        $out=shell_exec($command);
以下是浏览器上的结果:

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

可能是权限问题吗?比如php没有打开图形窗口的权限?
我真的不知道怎么解决这个问题。任何帮助都将非常感谢:)

使用PHP,您只显示命令行程序输出的内容,就像您在终端窗口中观看一样。它没有显示任何可能已创建的文件。当PHP由Web服务器执行时,它没有图形shell访问权限(这不是权限问题,它只是不在GUI上下文中运行),因此如果该程序需要图形用户上下文才能工作,然后你就遇到了一个根本性的问题,你无法真正解决这个问题——你无法从web(使用PHP或任何其他语言)成功地运行程序。不过,如果程序本身有选项使其不依赖GUI,那么可能值得研究一下。e、 通过对“octave命令行”的快速搜索,我发现它提到了一个“无gui”选项,您可以给该命令一个选项。我在今天之前从未遇到过这个应用程序,所以我不知道这是否对您有帮助,但它可能值得一试。我想,可能还有其他事情,请阅读文档。在通过PHP尝试之前,请自己在终端会话中进行测试,非常感谢您的解释。当你说php不在GUI环境下运行时,你是什么意思?我们不能改变吗?不,你不能改变。它在web服务器的用户上下文下运行,作为非图形用户运行(因为它基本上是一个自动服务,在与O/s交互时通常不需要图形,它只是发出命令)。您了解操作系统(特别是linux和macOS)有多种方式登录用户吗?-e、 g.在linux中,您可以使用或不使用X服务器登录。如果您使用X服务器登录,您将获得完整的桌面、正常的最终用户体验。但是如果您没有登录(例如,作为终端会话,或者如果您通过SSH远程登录),那么您只会得到命令行界面,其他什么都没有。类似地,在Windows中,虽然最终用户通常不能仅使用命令行登录,但作为后台服务运行的其他程序可以并且确实可以在非交互式和非图形化会话中运行。