如何在 iphone safari 中检测照片/视频是从相机拍摄还是从相机胶卷导入

2024-04-07

在我的网站上我有一个file input标签上传照片/视频。 当在 mobile safari 中打开网站并单击文件输入时,会打开一个包含 3 个选项的操作表take photo or Video, choose Existing and 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'] 值与实际日期时间进行比较,如果有几秒的差异,则可以假设它是刚才由手机拍摄的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 iphone safari 中检测照片/视频是从相机拍摄还是从相机胶卷导入 的相关文章

随机推荐