Skip to content

Instantly share code, notes, and snippets.

@zmiftah
Created January 3, 2014 07:17
Show Gist options
  • Save zmiftah/8234131 to your computer and use it in GitHub Desktop.
Save zmiftah/8234131 to your computer and use it in GitHub Desktop.
PHP: Get Image Dimension By Type
<?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