$path, 'filename' => $filename, 'extension' => $extension); return $cache_path; } /** * Gets the size the image should be resized to. * * This function takes into account the requested size, as well as the size of * the source image and the requesting screen size. * * @param resource $img_data * The image resource of the source image * * @return array * The width and height to resize to */ function fiftyone_degrees_get_size($img_data) { global $_fiftyone_degrees_needed_properties; $_fiftyone_degrees_needed_properties = array( 'ScreenPixelsWidth', 'ScreenPixelsHeight'); require_once '51Degrees.php'; global $_51d; global $_fiftyone_degrees_max_image_width; global $_fiftyone_degrees_max_image_height; global $_fiftyone_degrees_image_factor; global $_fiftyone_degrees_image_width_parameter; global $_fiftyone_degrees_image_height_parameter; global $_fiftyone_degrees_default_auto; if (!isset($_fiftyone_degrees_default_auto)) { $_fiftyone_degrees_default_auto = 50; } // The value of the auto flag. $auto = 'auto'; if (isset($_fiftyone_degrees_image_width_parameter)) { $width_param = $_fiftyone_degrees_image_width_parameter; } else { $width_param = 'w'; } if (isset($_fiftyone_degrees_image_height_parameter)) { $height_param = $_fiftyone_degrees_image_height_parameter; } else { $height_param = 'h'; } $source_width = imagesx($img_data); $source_height = imagesy($img_data); $source_ratio = $source_width / $source_height; $width_limit = $source_width; if (isset($_51d['ScreenPixelsWidth'])) { if ($_51d['ScreenPixelsWidth'] > $source_width) $width_limit = $_51d['ScreenPixelsWidth']; } if (isset($_fiftyone_degrees_max_image_width) && $_fiftyone_degrees_max_image_width > 0) { $width_limit = min($width_limit, $_fiftyone_degrees_max_image_width); } $height_limit = $source_height; if (isset($_51d['ScreenPixelsHeight'])) { if ($_51d['ScreenPixelsHeight'] > $source_height) $height_limit = $_51d['ScreenPixelsHeight']; } if (isset($_fiftyone_degrees_max_image_height) && $_fiftyone_degrees_max_image_height > 0) { $height_limit = min($height_limit, $_fiftyone_degrees_max_image_height); } if (isset($_GET[$width_param])) { $w = intval($_GET[$width_param]); if ($w != 0) { if ($w > $width_limit) { $w = $width_limit; } } else if ($_GET[$width_param] === $auto) { $w = $_fiftyone_degrees_default_auto; } } if (isset($_GET[$height_param])) { $h = intval($_GET[$height_param]); if ($h != 0) { if ($h > $height_limit) { $h = $height_limit; } } else if ($_GET[$height_param] === $auto) { $h = $_fiftyone_degrees_default_auto; } } if (!isset($w) && !isset($h)) { $w = $width_limit; $h = $width_limit / $source_ratio; } elseif (!isset($h)) { $h = $w / $source_ratio; } elseif (!isset($w)) { $w = $h * $source_ratio; } $width = intval($w); $height = intval($h); if(isset($_fiftyone_degrees_image_factor) && $_fiftyone_degrees_image_factor > 0) { $width = $_fiftyone_degrees_image_factor * intval(floor($width / $_fiftyone_degrees_image_factor)); $height = $_fiftyone_degrees_image_factor * intval(floor($height / $_fiftyone_degrees_image_factor)); } if ($width < $_fiftyone_degrees_image_factor) { $width = $_fiftyone_degrees_image_factor; } if ($height < $_fiftyone_degrees_image_factor) { $height = $_fiftyone_degrees_image_factor; } return array( 'width' => $width, 'height' => $height, 'source_width' => $source_width, 'source_height' => $source_height); } fiftyone_degrees_create_image();