gpt4 book ai didi

php - 第 5 行警告 exif_read_data(php3KLADx) : File not supported in/home/i/public_html/orientation. php

转载 作者:行者123 更新时间:2023-12-04 01:28:00 32 4
gpt4 key购买 nike

我得到 exif 来读取上传图像的方向。
问题是在某些图像中我收到此错误:

warning exif_read_data(php3KLADx): File not supported in /home/i/public_html/orientation.php on line 5



任何想法如何避免这种情况?
<?php
function exif_orientation($file_tmp) {

$image = imagecreatefromstring(file_get_contents($file_tmp));
$exif = exif_read_data($file_tmp);

if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
imagejpeg($image, $file_tmp, 90);
}
}
?>

最佳答案

你应该这样做,如下所示:

if (!function_exists('imageOrientation'))
{
function imageOrientation(string $directory)
{
if(file_exists($directory))
{
$destination_extension = strtolower(pathinfo($directory, PATHINFO_EXTENSION));
if(in_array($destination_extension, ["jpg","jpeg"]) && exif_imagetype($directory) === IMAGETYPE_JPEG)
{
if(function_exists('exif_read_data'))
{
$exif = exif_read_data($directory);
if(!empty($exif) && isset($exif['Orientation']))
{
$orientation = $exif['Orientation'];
switch ($orientation)
{
case 2:
$flip = 1;
$deg = 0;
break;
case 3:
$flip = 0;
$deg = 180;
break;
case 4:
$flip = 2;
$deg = 0;
break;
case 5:
$flip = 2;
$deg = -90;
break;
case 6:
$flip = 0;
$deg = -90;
break;
case 7:
$flip = 1;
$deg = -90;
break;
case 8:
$flip = 0;
$deg = 90;
break;
default:
$flip = 0;
$deg = 0;
}
$img = imagecreatefromjpeg($directory);
if($deg !== 1 && $img !== null)
{
if($flip !== 0)
{
imageflip($img,$flip);
}
$img = imagerotate($img, $deg, 0);
imagejpeg($img, $directory);
}
}
}
}
}
}
}

关于php - 第 5 行警告 exif_read_data(php3KLADx) : File not supported in/home/i/public_html/orientation. php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52174789/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com