图片不旋转

Images aren't rotating

好的。一段时间以来,我一直在寻找解决方案,但我似乎无法弄清楚为什么使用 PHP.

在我的 Debian 服务器上图像没有旋转
$content_id = escapeQuery($_GET['id']); // escapeQuery is a function i created that removes all the nasty SQL injection methods
$sql = mysqli_query($mysqli, "SELECT * FROM images WHERE id = '$content_id'");
$data_array[] = $sql->fetch_assoc();
$image_url = $data_array[0]['file_name'];

$file_extension = explode('.', $image_url);

if (isset($_GET['rotate']) && !empty($_GET['rotate'])) {
  $rotate_images = array('original', 'thumbnail', 'resized');

  foreach ($rotate_images as $value) {

    $filename = '/var/www/sitename.com/images/'.$value.'/' . $image_url;
    $degrees = 90;

    if ($file_extension[1] === 'jpg' or $file_extension[1] === 'jpeg') {
      $source = imagecreatefromjpeg($filename);
      $rotate = imagerotate($source, $degrees, 0);
      imagejpeg($rotate);
    } elseif ($file_extension[1] === 'png') {
      $source = imagecreatefrompng($filename);
      $rotate = imagerotate($source, $degrees, 0);
      imagepng($rotate);
    } elseif ($file_extension[1] === 'webp') {
      $source = imagecreatefromwebp($filename);
      $rotate = imagerotate($source, $degrees, 0);
      imagewebp($rotate);
    } elseif ($file_extension[1] === 'gif') {
      $source = imagecreatefromgif($filename);
      $rotate = imagerotate($source, $degrees, 0);
      imagegif($rotate);
    } elseif ($file_extension[1] === 'bmp') {
      $source = imagecreatefrombmp($filename);
      $rotate = imagerotate($source, $degrees, 0);
      imagebmp($rotate);
    } else {
    // some action here 
    }
  }
  imagedestroy($rotate);
  // some action here 
  exit;
}

我尝试解决的问题:

最后我自己解决了这个问题。

它没有被非常清楚地记录下来,但是要将图像保存到服务器,您必须像这样在 imagejpeg 函数中定义图像的确切位置 imagejpeg($rotate, $destination);

希望这对以后的任何人都有帮助:)