Created
January 3, 2014 07:17
-
-
Save zmiftah/8234131 to your computer and use it in GitHub Desktop.
PHP: Get Image Dimension By Type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getDimensions($filename, $filetype) | |
{ | |
$image = null; | |
switch ($filetype) { | |
case 'image/gif': | |
$image = imagecreatefromgif($filename); | |
break; | |
case 'image/jpeg': | |
case 'image/pjpeg': | |
$image = imagecreatefromjpeg($filename); | |
break; | |
case 'image/png': | |
$image = imagecreatefrompng($filename); | |
break; | |
case 'image/bmp': | |
$image = imagecreatefromwbmp($filename); | |
} | |
if ($image != null) { | |
return array( | |
'w'=>imagesx($image), | |
'h'=>imagesy($image) | |
); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment