= H) { // if ($center) { $sdy = round(($nh - H) / 2); } if ($center) { $sdy = round( (($nh - H) / 2) * ($sw / $nw) ); } } else { // if height is to small "fit height" $nh = H; $nw = round($sw * ($nh / $sh)); if ($center) { $sdx = round( (($nw - W) / 2) * ($sh / $nh) ); } } // Create a blank image $scaledimage = imagecreatetruecolor(W, H); // Copy from source and resize imagecopyresampled($scaledimage, $src, 0, 0, $sdx, $sdy, W, H, $sw-(2 * $sdx), $sh-(2 * $sdy)); // Clean up memory imagedestroy($src); $base = date('Ymd_His')."_".getmypid(); $fsname = IMAGEFOLDER.$base.".png"; $thname = IMAGEFOLDER.$base."_th.png"; // Write to a file imagepng($scaledimage,$fsname); // Create a blank image $scaledthumb = imagecreatetruecolor(TH_W, TH_H); // Copy from source and resize imagecopyresampled($scaledthumb, $scaledimage, 0, 0, 0, 0, TH_W, TH_H, W, H); // Write to a file imagepng($scaledthumb,$thname); // Clean up memory imagedestroy($scaledthumb); imagedestroy($scaledimage); return $base; } $upload = $_FILES['uploadedfile']['tmp_name']; $uploadWorked = false; if (is_uploaded_file($upload)) { $base = processimage($upload); if ($base): playlist_add($base, $_REQUEST['insertbefore']); $uploadWorked = true; header('Location: success.php'); endif; } if (!$uploadWorked): header('Location: error.php'); endif; ?>