在我的网站上,我有一个file input
标签来上传照片/视频。
在移动浏览器中打开网站并单击文件输入时,将打开一个带有3个选项take photo or Video
,choose Existing
和cancel
的操作表。
无论如何,在js中是否可以确定文件是从相机(take photo or video
)拍摄的,还是从相机胶卷中导入的(choose existing
)?
最佳答案
我有一个从中实现的php解决方案,我不确定这对您有帮助,但是下面是代码:
<?php
$camera = cameraUsed("C:\Users\Ale\Pictures\sep7imodia.jpg");
echo "Camera Used: " . $camera['make'] . " " . $camera['model'] . "<br />";
echo "Exposure Time: " . $camera['exposure'] . "<br />";
echo "Aperture: " . $camera['aperture'] . "<br />";
echo "ISO: " . $camera['iso'] . "<br />";
echo "Date Taken: " . $camera['date'];
// This function is used to determine the camera details for a specific image. It returns an array with the parameters.
function cameraUsed($imagePath) {
// Check if the variable is set and if the file itself exists before continuing
if ((isset($imagePath)) and (file_exists($imagePath))) {
// There are 2 arrays which contains the information we are after, so it's easier to state them both
$exif_ifd0 = read_exif_data($imagePath ,'IFD0' ,0);
$exif_exif = read_exif_data($imagePath ,'EXIF' ,0);
//error control
$notFound = "Unavailable";
// Make
if (@array_key_exists('Make', $exif_ifd0)) {
$camMake = $exif_ifd0['Make'];
} else { $camMake = $notFound; }
// Model
if (@array_key_exists('Model', $exif_ifd0)) {
$camModel = $exif_ifd0['Model'];
} else { $camModel = $notFound; }
// Exposure
if (@array_key_exists('ExposureTime', $exif_ifd0)) {
$camExposure = $exif_ifd0['ExposureTime'];
} else { $camExposure = $notFound; }
// Aperture
if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED'])) {
$camAperture = $exif_ifd0['COMPUTED']['ApertureFNumber'];
} else { $camAperture = $notFound; }
// Date
if (@array_key_exists('DateTime', $exif_ifd0)) {
$camDate = $exif_ifd0['DateTime'];
} else { $camDate = $notFound; }
// ISO
if (@array_key_exists('ISOSpeedRatings',$exif_exif)) {
$camIso = $exif_exif['ISOSpeedRatings'];
} else { $camIso = $notFound; }
$return = array();
$return['make'] = $camMake;
$return['model'] = $camModel;
$return['exposure'] = $camExposure;
$return['aperture'] = $camAperture;
$return['date'] = $camDate;
$return['iso'] = $camIso;
return $return;
} else {
return false;
}
}
?>
您可以将$ camera ['date']值与实际日期时间进行比较,如果有几秒钟的差异,则可以假定它是手机刚刚拍摄的。
关于javascript - 如何检测照片/视频是从iPhone的Safari相机拍摄的还是从相机胶卷导入的,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23774903/