PHP创建缩略图,将垂直图像更改为水平
您好…我正在动态调整JPGs目录的大小。这些照片在本质上是随机水平或垂直的。我的脚本(包括在下面)工作正常-除了在一个特定的情况下。在这种情况下,我将照片直接从存储卡传输到最终目录,从中创建拇指。在这种情况下-我的垂直照片生成水平拇指 如果我处理一个包含已处理、调整大小或未调整大小的图像的文件夹,则不会发生此问题。垂直照片在相机和存储卡上旋转,在我的本地驱动器上,垂直预览为垂直,这证明了这一点。但是,如果我通过缩略图脚本运行未触及的文件,它会顺时针垂直旋转90度 有没有聪明人有什么想法?:) 我还曾想过在界面中放置一个“rotate”按钮,但我无法让php函数rotateimage()工作。示例很简单…没有错误,但在浏览器中我得到了一英里的符号和文本。你以前见过吗 谢谢PHP创建缩略图,将垂直图像更改为水平,php,Php,您好…我正在动态调整JPGs目录的大小。这些照片在本质上是随机水平或垂直的。我的脚本(包括在下面)工作正常-除了在一个特定的情况下。在这种情况下,我将照片直接从存储卡传输到最终目录,从中创建拇指。在这种情况下-我的垂直照片生成水平拇指 如果我处理一个包含已处理、调整大小或未调整大小的图像的文件夹,则不会发生此问题。垂直照片在相机和存储卡上旋转,在我的本地驱动器上,垂直预览为垂直,这证明了这一点。但是,如果我通过缩略图脚本运行未触及的文件,它会顺时针垂直旋转90度 有没有聪明人有什么想法?:) 我
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
// open the directory
$dir = opendir( $pathToImages );
// loop through it, looking for any/all JPG files:
while (false !== ($fname = readdir( $dir ))) {
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
if ( strtolower($info['extension']) == 'jpg' )
{
echo "Creating thumbnail for {$fname} <br />";
// load image and get image size
$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
$width = imagesx( $img );
$height = imagesy( $img );
// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );
// create a new tempopary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );
// copy and resize old image into new image
//imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
imagecopyresampled( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
// save thumbnail into a file
imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
}
}
// close the directory
closedir( $dir );
}
函数createThumbs($pathToImages、$pathToThumbs、$thumbWidth)
{
//打开目录
$dir=opendir($pathToImages);
//循环浏览,查找任何/所有JPG文件:
while(false!=($fname=readdir($dir))){
//解析扩展的路径
$info=pathinfo($pathToImages.$fname);
//仅当这是JPEG图像时才继续
如果(strtolower($info['extension'])=='jpg')
{
echo“为{$fname}
创建缩略图”;
//加载图像并获取图像大小
$img=imagecreatefromjpeg(“{$pathToImages}{$fname}”);
$width=imagesx($img);
$height=imagesy($img);
//计算缩略图大小
$new_width=$thumbWidth;
$new_height=地板($height*($thumbWidth/$width));
//创建一个新的tempopary图像
$tmp\u img=ImageCreateTureColor($new\u width,$new\u height);
//将旧图像复制并调整大小为新图像
//imagecopyresized($tmp\u img,$img,0,0,0,$new\u width,$new\u height,$width,$height);
imagecopyresampled($tmp_img,$img,0,0,0,$new_width,$new_height,$width,$height);
//将缩略图保存到文件中
图像jpeg($tmp_img,“{$pathToThumbs}{$fname}”);
}
}
//关闭目录
closedir($dir);
}
是否可能在最初的3个变量中向函数传递高度而不是宽度?这可能会造成这个问题。我们没有传递这些变量的代码,您可能想把它放上去 通过“垂直”和“水平”,您指的是拍摄照片时相机的方向吗?