Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 上传脚本、裁剪/剪切缩略图_Php_Image_Crop_Chop - Fatal编程技术网

Php 上传脚本、裁剪/剪切缩略图

Php 上传脚本、裁剪/剪切缩略图,php,image,crop,chop,Php,Image,Crop,Chop,我试图创建一个图像上传系统,但遇到了一个问题。系统上载插入的图像并创建缩略图 允许用户提供缩略图的宽度和高度。当图像是200px乘以100px,用户说缩略图的宽度是10px,高度是20px时,系统必须拉伸图像,这是我不希望发生的。我希望系统使用Imagick函数切掉图像的一部分,以便在图像通过脚本时获得正常的缩略图和图像 该函数的使用方式如下: chopImage ( width of the chopped area , height of the chopped area , x coord

我试图创建一个图像上传系统,但遇到了一个问题。系统上载插入的图像并创建缩略图

允许用户提供缩略图的宽度和高度。当图像是200px乘以100px,用户说缩略图的宽度是10px,高度是20px时,系统必须拉伸图像,这是我不希望发生的。我希望系统使用Imagick函数切掉图像的一部分,以便在图像通过脚本时获得正常的缩略图和图像

该函数的使用方式如下:

chopImage ( width of the chopped area , height of the chopped area , x coordinate of topleft corner of chopped area , y coordinate of topleft corner of chopped area )
php上传系统的标准配置:

$image = $_FILES["image"]["name"];
            $imgtemp = $_FILES["image"]["tmp_name"];
            $imgtype = $_FILES["image"]["type"];
            $imgsize = $_FILES["image"]["size"];    

if(!$image){
        if($image_enabled ==2){
            $errors[] = "You didn't selected an image to upload";
            }
        } else {
    if( $imgtype == 'image/jpeg' ){ $filetype= '.jpg'; }else{ $filetype= str_replace ( 'image/', '', $imgtype ); }

    $path= 'images/' . md5( rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 ) ) . '.jpg';
    $thumb_path= 'images/thumb_' . md5( rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 ) . rand( 0, 1000 ) ) . '.jpg';
    $imgsize2= getimagesize( $imgtemp );
    $width= $imgsize2[0];
    $height= $imgsize2[1];

    $maxwidth= 1281;
    $maxheight= 721;
    $allowed= array( 'image/png', 'image/jpeg', 'image/gif', );

    if( in_array( $imgtype, $allowed ) ){

        if( $width < $maxwidth && $height < $maxheight ){

        if( $imgsize < 5242880 ){
当我运行这个脚本时,它只上传普通图像。缩略图未上载。 我想imagick函数并不经常使用,因为在互联网上找不到任何使用imagick函数的上传教程。
有人能帮我吗?

您的代码看起来有点混乱。。。这是否符合你的预期

if(!isEmpty($image_thumbheight) || !isEmpty($image_thumbwidth)){
    $image_crop = new Imagick( $imgtmp );
    $image_crop->cropImage( $image_thumbwidth, $image_thumbheight, 0, $height );
    $image_crop->writeImage( $thumb_path );

    move_uploaded_file( $imgtemp, $path );
    echo "Image is successfully uploaded.";
}
if(!isEmpty($image_thumbheight) || !isEmpty($image_thumbwidth)){
    $image_crop = new Imagick( $imgtmp );
    $image_crop->cropImage( $image_thumbwidth, $image_thumbheight, 0, $height );
    $image_crop->writeImage( $thumb_path );

    move_uploaded_file( $imgtemp, $path );
    echo "Image is successfully uploaded.";
}