rendered paste body<?phpif (!function_exists("resize_image")) { function resize_image($old_file, $sizes = array('150' => array(150,150))) { $old_dir = pathinfo($old_file, PATHINFO_DIRNAME) . '/'; $file_name = pathinfo($old_file, PATHINFO_FILENAME); $photo_data = getimagesize($old_file); if ($photo_data['mime'] == 'image/jpeg') { $img = imagecreatefromjpeg($old_file); } elseif ($photo_data['mime'] == 'image/png') { $img = imagecreatefrompng($old_file); } elseif ($photo_data['mime'] == 'image/gif') { $img = imagecreatefromgif($old_file); } else { throw new Exception('Unknown file type: ' . $photo_data['mime']); exit; } $src_w = imagesx($img); $src_h = imagesy($img); foreach ($sizes as $sizename => $size) { list($size_x, $size_y) = $size; // 0 = x, 1 = y $outimg = imagecreatetruecolor($size_x, $size_y); $black = imagecolorallocate($outimg, 0, 0, 0); $dst_x = $dst_y = 0; // Set the background to transparent imagecolortransparent($outimg, $black); if ($src_h > $src_w) { // Portrait $scale = $src_h / $size_y; } else { // Landscape $scale = $src_w / $size_x; } // Scale the sizes... $dst_w = $src_w / $scale; $dst_h = $src_h / $scale; // Centre the image in the X & Y axes $dst_x = ($size_x - $dst_w) / 2; $dst_y = ($size_y - $dst_h) / 2; // Resizing happens here... imagecopyresampled($outimg, $img, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $src_w, $src_h); $fname = $old_dir . $sizename . '_' . $file_name . '.png'; imagepng($outimg, $fname); imagedestroy($outimg); unset($black, $outimg); } }}