function image_resize_to($img, $width, $height) { $src_w = image_width($img); $src_h = image_height($img); $img_new = imagecreatetruecolor($width, $height); imagecopyresampled($img_new, $img, 0, 0, 0, 0, $width, $height, $src_w, $src_h); return $img_new; }
$TypeName = $Type === 'avatar' ? 'avatar' : 'second avatar'; } elseif ($Type === 'donoricon') { $MaxFileSize = 64 * 1024; // 64 kB $MaxImageHeight = 100; // pixels $TypeName = 'donor icon'; } $Height = image_height($FileType, $Data); if (strlen($Data) > $MaxFileSize || $Height > $MaxImageHeight) { // Sometimes the cached image we have isn't the actual image if ($Cached) { $Data2 = @file_get_contents($URL, 0, stream_context_create(array('http' => array('timeout' => 15)))); } else { $Data2 = $Data; } if (strlen($Data2) > $MaxFileSize || image_height($FileType, $Data2) > $MaxImageHeight) { require_once SERVER_ROOT . '/classes/mysql.class.php'; require_once SERVER_ROOT . '/classes/time.class.php'; $DBURL = db_string($URL); $AdminComment = ucfirst($TypeName) . " reset automatically (Size: " . number_format(strlen($Data) / 1024) . " kB, Height: " . $Height . "px). Used to be {$DBURL}"; $PrivMessage = SITE_NAME . " has the following requirements for {$TypeName}s:\n\n" . "[b]" . ucfirst($TypeName) . "s must not exceed " . $MaxFileSize / 1024 . " kB or be vertically longer than {$MaxImageHeight}px.[/b]\n\n" . "Your {$TypeName} at {$DBURL} has been found to exceed these rules. As such, it has been automatically reset. You are welcome to reinstate your {$TypeName} once it has been resized down to an acceptable size."; reset_image($UserID, $Type, $AdminComment, $PrivMessage); } } } if (!isset($FileType)) { img_error('timeout'); } header("Content-type: image/{$FileType}"); echo $Data;