0

我正在尝试将上传/裁剪 php 脚本用于我想要在网站上的图像上传表单。它为任何听说过它的人使用 ImageManipulator.php,并且上传工作正常,但实际的修剪/裁剪和添加到文件夹不起作用。这是我的代码:

//Avatar Preferences
$avatar = mysqli_real_escape_string($con, $_REQUEST["avatar"]);
// include ImageManipulator class
require_once('../scripts/ImageManipulator.php');

if ($_FILES[$avatar]['error'] > 0) {
    echo "Error: " . $_FILES[$avatar]['error'] . "<br />";
} else {
    // array of valid extensions
    $validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
    // get extension of the uploaded file
    $fileExtension = strrchr($_FILES[$avatar]['name'], ".");
    // check if file Extension is on the list of allowed ones
    if (in_array($fileExtension, $validExtensions)) {
        $newNamePrefix = time() . '_';
        $manipulator = new ImageManipulator($_FILES[$avatar]['tmp_name'])or die(mysqli_error());
        $width  = $manipulator->getWidth();
        $height = $manipulator->getHeight();
        $centreX = round($width / 2);
        $centreY = round($height / 2);
        // our dimensions will be 200x130
        $x1 = $centreX - 100; // 200 / 2
        $y1 = $centreY - 65; // 130 / 2

        $x2 = $centreX + 100; // 200 / 2
        $y2 = $centreY + 65; // 130 / 2

        // center cropping to 200x130
        $newImage = $manipulator->crop($x1, $y1, $x2, $y2);
        // saving file to uploads folder
        $manipulator->save('../uploads/' . $newNamePrefix . $_FILES[$avatar]['name']);
        echo 'Done ...';
    } else {
        echo 'You must upload an image...';
    }
}

你们中有人看到这里有潜在的问题吗?谢谢

4

0 回答 0