Php 图像不旋转

Php 图像不旋转,php,Php,我正在尝试使用php imagerotate函数旋转图像,但它不起作用。 GD库也在运行中 我试过这个 public function rotate() { $targ_w = 240; $targ_h = 180; $jpeg_quality = 100; $degrees = 90; $src = "/photos/sunset.jpg";

我正在尝试使用php imagerotate函数旋转图像,但它不起作用。 GD库也在运行中

我试过这个

public function rotate()
       {
            $targ_w = 240;
            $targ_h = 180;
            $jpeg_quality = 100;
            $degrees = 90;


           $src = "/photos/sunset.jpg";

           $image = imagecreatefromjpeg($src);

           $rotatedImage = imagerotate($image,$degrees,0);

           imagejpeg( $rotatedImage,$src,$jpeg_quality);

           imagedestroy($rotatedImage);

            die();
        }

您必须输出旋转图像(通过
$rotatedImage
而不是
$image
):


您正在将未更改的
$image
输出到文件。您应该输出旋转的一个

imagejpeg( $rotatedImage,$name ,$jpeg_quality);
第二件事-你的图像是空的。它只定义了宽度和高度,但内部没有内容。您定义了一个
$src
变量,但根本不使用它。
也许您想用以下内容替换
imagecreatetruecolor

$src = "/photos/sunset.jpg";
$image = imagecreatefromjpeg($src);

如果您试图显示图像,则需要更改:

header('Content-type: image/jpeg'); //Add jpeg header
imagejpeg( $rotatedImage, NULL, 100);  //<-- Notice i remove the $src parameter
标题('Content-type:image/jpeg')//添加jpeg头
图像JPEG($rotateImage,NULL,100)//<代码>

定义不工作。输出中有错误吗?无错误检查,错误报告新图像文件(out.jpg)的维度是什么?是否要在impagejpeg函数中输出$RotateImage?向何处传递维度?您更新了答案,但仍然显示
$image
而不是
$RotateImage
,是否更改了此选项<代码>图像jpeg($rotateImage,$name,$jpeg\u-quality)我几乎可以肯定他更新了问题。。。。对不起,我的错。嗯,Swap-check@matewka-answer,看起来不错输出图像是什么样子的?它是180像素宽,240像素高吗?它是完全白色的还是充满了
照片/sunset.jpg
?试图在同一个文件夹中旋转相同的图像。是的,我注意到了。你能严格回答我在上述评论中提出的问题吗?根据你的建议,代码运行良好。我的问题在于没有在$src中获得img。
header('Content-type: image/jpeg'); //Add jpeg header
imagejpeg( $rotatedImage, NULL, 100);  //<-- Notice i remove the $src parameter
      <?php
       // File and rotation
       $filename = 'test.jpg';
       $degrees = 180;
       // Content type
       header('Content-type: image/jpeg');
       // Load
       $source = imagecreatefromjpeg($filename);
       // Rotate
       $rotate = imagerotate($source, $degrees, 0);
       // Output
       imagejpeg($rotate);
       // Free the memory
       imagedestroy($source);
       imagedestroy($rotate);
        ?>