I need to know whether I can trust this code to get the image format:
$image = new Imagick($path);
$format = $image->getImageFormat();
Or should I still check extension, mime type, etc like usual?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can trust it much more than just checking the extension of the file (
pic.jpgfor example) with simple php string functions.You can have an experiment. Rename a
.jpgimage file so that it becomes.png, for example. Use simple tools of the Windows “Rename”. So it seems now that the image is a.pngimage.But try
Imagickincmdwith-verbosecommand, like this:And you will see that in reality the image is
.jpg. The same is with your$image->getImageFormat();somewhere in your program.Imagickis powerful tool. Unfortunately there is much less information about its API in PHP than GD has.