Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How get camera make and model from Image using PHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 822
    Comment on it

    Hello, Reader's if you are uploading images for website gallery and looking for extract the Camera make and model from it, Then  PHP offers you to do this via EXIF meta.

    Every original digital photo contains the detail of Camera model and various others details like Date Taken and software used to edit the image.

    So let's get working on this-
    Step 1: Create a single HTML form to upload the image and its code will go like this

     <form method="post" autocomplete = "off" action= "<?php echo base_url();?>UploadImages/UploadPlacesImages/" enctype="multipart/form-data">
                <p class="addPhoto">You can add 5 photos at a time</p>           
                <p><span class ="error">**Upload atleast 2 images</span></p>
                <br>
              
                <input type="submit" value="Upload" name="submit" class="browsebtnEdit">
             
                <a  class="browsebtnEdit" type="button" href="<?php echo base_url(); ?>Uploads/addImage/">Upload</a>
              
        </form>the
                <br>
              
                <input type="submit" value="Upload" name="submit" class="browsebtnEdit">
             
                <a  class="browsebtnEdit" type="button" href="<?php echo base_url(); ?>Uploads/addImage/">Upload</a>
              
        </form>

    Now create a function with name addImage inside the Uploads controller for getting the image and extract the Exif data from it. It's Code will go like this:-

     $image_name = $result['name']; //file name
                $image_size = $_FILES['placeImages']['size']; //file size
                $image_temp = $_FILES['placeImages']['tmp_name']; //file temp
                $image_type = $_FILES['placeImages']['type']; //file type
    
                $image_name = str_replace(' ', '_', $image_name); //replacing all the blackspaces
                switch(strtolower($image_type))
                  { //determine uploaded image type 
                      //Create new image from file
                      case 'image/png': 
                      $image_resource =  imagecreatefrompng($image_temp);
                      break;
                      case 'image/gif':
                      $image_resource =  imagecreatefromgif($image_temp);
                      break;          
                      case 'image/jpeg': case 'image/pjpeg':
                      $image_resource = imagecreatefromjpeg($image_temp);
                      break;
                      default:
                      $image_resource = false;
                  }           

    if you are uploading multiple images then you need to declare a variable i for individually getting the image data in a single array and put the line as below:-

     $exif = exif_read_data($image_temp_original, 0, true); 
                              $final_img_info['make'] = @$exif['IFD0']['Make'];         
                              $final_img_info['model'] = @$exif['IFD0']['Model'];         
                              $final_img_info['ApertureFNumber'] = @$exif['COMPUTED']['ApertureFNumber']; 
                              $final_img_info['softwareUsed'] = @$exif['IFD0']['Software'];        
                              $final_img_info['EditDateTime'] = @$exif['IFD0']['DateTime'];  
                              $final_img_info['ISO'] = @$exif['EXIF']['ISOSpeedRatings'];  
                              $final_img_info['DateTimeOriginal'] = @$exif['EXIF']['DateTimeOriginal'];  
                              $final_img_info['ShutterSpeedValue'] = @$exif['EXIF']['ShutterSpeedValue'];  
                              $final_img_info['Flash'] = @$exif['EXIF']['Flash'];  
                              $final_img_info['FocalLength'] = @$exif['EXIF']['FocalLength'];
                              $final_img_info['UserComment'] = @$exif['COMPUTED']['UserComment'];
                              $placeImages_uploaded[$i]['image'] = $newName; 
                              $placeImages_uploaded[$i]['details'] = $final_img_info;    

    Now when you print the array $placeImages_uploaded. The result will start printing the details of Image as Camera make, Camera Model, Date capture, ISO , Focus and shutter speed.
    You need to save this data at the same time because once the image is compress and uploaded all of these details will be gone for forever. 

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: