0

我正在尝试从节点服务器访问 php 页面,以便生成一些缩略图。问题是当我从节点发出 jquery.get 请求时它没有生成图像。不过,如果我从浏览器中点击页面,它会完美运行。

这是php代码:

<?php

$thumbsFolder = 'output/thumbs/';
$mediumFolder = 'output/medium/';

$originals = glob("output/*.jpg");
$thumbs = glob("output/thumbs/*.jpg");

// only process the images that are missing
$diff = array_diff($originals, $thumbs);
foreach ($diff as $file) {
  processImage($file, $thumbsFolder, 150);
  processImage($file, $mediumFolder, 600);
}

function processImage($imagePath, $outputFolder, $targetWidth){

  $imageSize = getimagesize($imagePath);
  $originalWidth = $imageSize[0];
  $originalHeight = $imageSize[1];
  $targetHeight = round($originalHeight * $targetWidth / $originalWidth);

  $urlElements = explode("/", $imagePath);
  $fileName = array_pop($urlElements);
  $fileName = explode(".", $fileName);
  $ext = array_pop($fileName);
  $newFilePath = $outputFolder.join($fileName, "").".".$ext;

  $im = imagecreatefromjpeg($imagePath);
  $sm = imagecreatetruecolor($targetWidth, $targetHeight);
  imagealphablending($sm, false);
  imagecopyresampled($sm, $im, 0, 0, 0, 0, $targetWidth, $targetHeight, $originalWidth, $originalHeight);
  imagejpeg($sm, $newFilePath, 75);

}

?>

这是到达端点的节点脚本。

$.get("http://absolutepath.com/pi-lapse/thumb-gen.php", function(e){console.log(e)})

我也试过卷曲,但没有奏效。

4

0 回答 0