protected function file_contents_exist($url, $response_code = 200) { if (defined('STRICT_TYPES') && CAMEL_CASE == '1') { return (bool) self::parameters(['url' => DT::STRING, 'response_code' => DT::UINT8])->call(__FUNCTION__)->with($url, $response_code)->returning(DT::BOOL); } else { return (bool) file_contents_exist($url, $response_code); } }
function get_image_size_percentage($filename, $percentage) { function file_contents_exist($url) { $headers = get_headers($url); if (substr($headers[0], 9, 3) == 200) { return TRUE; } else { return FALSE; } } if (file_contents_exist($filename)) { $image_file = getimagesize($filename); $width = $image_file[0] / 100 * $percentage; $height = $image_file[1] / 100 * $percentage; return (object) array('width' => $width, 'height' => $height); } else { return NULL; } }
function get_image_scale_size($filename, $max_w = 100, $max_h = NULL) { function file_contents_exist($url) { $headers = get_headers($url); if (substr($headers[0], 9, 3) == 200) { return TRUE; } else { return FALSE; } } if (is_null($max_h)) { $max_h = $max_w; } if (file_contents_exist($filename)) { list($img_w, $img_h) = getimagesize($filename); $f = min($max_w / $img_w, $max_h / $img_h, 1); $w = round($f * $img_w); $h = round($f * $img_h); // return array($w, $h); return (object) array('width' => $w, 'height' => $h); } return NULL; }