Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中,当宽度大于高度时自动旋转图像_Php_Css_Image_Image Rotation_Autorotate - Fatal编程技术网

在PHP中,当宽度大于高度时自动旋转图像

在PHP中,当宽度大于高度时自动旋转图像,php,css,image,image-rotation,autorotate,Php,Css,Image,Image Rotation,Autorotate,我过去问过,但我不确定我们是否理解&我仍然没有解决办法。 我需要优雅的解决方案时; 我有照片600x800&我需要在我的网站上显示它旋转90度,所以结果将是,当我打印php页面时,所有照片将自动垂直 e、 g。 我有很多照片,有两种:800x600和600x800。 我需要在我的php页面上显示所有的原始800x600和所有600x800旋转90度 我需要一些非常简单的解决方案,我完全疯了。一些功能可以旋转宽度大于高度的图像 非常感谢。用于检测图像宽度,如果宽度为800px,则添加如下内联css

我过去问过,但我不确定我们是否理解&我仍然没有解决办法。 我需要优雅的解决方案时; 我有照片600x800&我需要在我的网站上显示它旋转90度,所以结果将是,当我打印php页面时,所有照片将自动垂直

e、 g。 我有很多照片,有两种:800x600和600x800。 我需要在我的php页面上显示所有的原始800x600和所有600x800旋转90度

我需要一些非常简单的解决方案,我完全疯了。一些功能可以旋转宽度大于高度的图像

非常感谢。

用于检测图像宽度,如果宽度为800px,则添加如下内联css

style="-moz-transform: rotate(90deg); -webkit-transform: rotate(90deg); -o-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg);"

使用PHP函数
getimagesize()
您可以获得图像的
宽度
高度

  list($width, $height) = getimagesize($imageUrl);
然后,在模板中:

  <?php if($width > $height): ?>
        //put css here as you want
  <?php else: ?>
        //put css here as you want
  <?php endif; ?>

//根据需要在此处放置css
//根据需要在此处放置css
getimagesize()函数将为您提供宽度和高度,通过使用,您可以将图像旋转到任何所需角度

试试这个:-

<?php
// File and rotation
$filename = 'php.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);
?>


因此每个图像有2个;800x600和600x800?您当前的输出是多少?您可以发布您的php逻辑吗?您可以使用GD或ImageMagick在服务器上旋转图像,也可以使用CSS转换在浏览器中旋转图像。这不是正确的格式:--echo(“”;--?:/这不是工作