Example #1
0
 /**
  * Using the given $source_path of an image, return the GD image if possible
  * @param string $source_path The path of the source image
  * @param string $type_file The file type of the source image
  * @return mixed GD image if successful, false otherwise
  */
 function getSrcImg($source_path, $type_file = false)
 {
     if (!function_exists('imagetypes')) {
         return false;
     }
     thumbnail::AdjustMemoryLimit();
     if ($type_file !== false) {
         $img_type = thumbnail::getType($type_file);
     } else {
         $img_type = thumbnail::getType($source_path);
     }
     $supported_types = imagetypes();
     //start
     switch ($img_type) {
         case 'jpg':
         case 'jpeg':
             if ($supported_types & IMG_JPG) {
                 return imagecreatefromjpeg($source_path);
             }
             break;
         case 'gif':
             return imagecreatefromgif($source_path);
             break;
         case 'png':
             if ($supported_types & IMG_PNG) {
                 return imagecreatefrompng($source_path);
             }
             break;
         case 'bmp':
             if ($supported_types & IMG_WBMP) {
                 return imagecreatefromwbmp($source_path);
             }
             break;
         default:
             //message('not supported for thumbnail: '.$img_type);
             return false;
     }
     return false;
 }