Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to verify an image format with php

Tags:

php

format

image

i need to verify a lot of images files for an application, the situations is that i have 10 directories with almost 10,000 images on each one, something like 100,000 files. Those files are supposed to be gif files but a lot of them (and really mean a lot) were jpg files that a designer change the extension from .jpg to .gif without converting the file format. This is causing the application crash, it creates pdf files using those images, and if i tell to the programm that use the file somefile.gif but it really is a jpg with the extension renamed the pdf creator crashes. I don't want to open every file in something like irfanview or photoshop to verify the format and then modify it if is necessary. Is there a library, class, plugin or something in php or another language that tell me the format of files with no base in the extension but in the headers of the file?

I can't find any ideas to do this, some one can help me?

Thanxs a lot in advance!!!

like image 483
Brutal Legion Avatar asked Nov 22 '25 11:11

Brutal Legion


1 Answers

I personally use exif_imagetype for a true verification rather than checking extensions or mime types.

like image 69
maiorano84 Avatar answered Nov 25 '25 03:11

maiorano84