Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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';s调整大小\u裁剪\u图像?_Php_Image_Flutter_Dart_Image Processing - Fatal编程技术网

飞镖/颤振替代PHP';s调整大小\u裁剪\u图像?

飞镖/颤振替代PHP';s调整大小\u裁剪\u图像?,php,image,flutter,dart,image-processing,Php,Image,Flutter,Dart,Image Processing,目前,我正在使用PHP的resize_crop_图像调整服务器上的头像大小。下面的代码拍摄一幅图像,对其进行裁剪和调整大小,使其精确到500px X 500px的正方形 调整裁剪图像的大小(500500,$filename,$filename) 但是我想把这个过程从服务器转移到flutter应用程序。我在pub.dev上看到的大多数插件都使用了裁剪工具来裁剪图像,这是一种过度使用。但是我希望这个函数能够像我目前在PHP中所做的那样自动实现 这是调整大小的裁剪图像代码 function resiz

目前,我正在使用PHP的resize_crop_图像调整服务器上的头像大小。下面的代码拍摄一幅图像,对其进行裁剪和调整大小,使其精确到500px X 500px的正方形

调整裁剪图像的大小(500500,$filename,$filename)

但是我想把这个过程从服务器转移到flutter应用程序。我在pub.dev上看到的大多数插件都使用了裁剪工具来裁剪图像,这是一种过度使用。但是我希望这个函数能够像我目前在PHP中所做的那样自动实现

这是调整大小的裁剪图像代码

function resize_crop_image($max_width, $max_height, $source_file, $dst_dir, $quality = 100){
        $imgsize = getimagesize($source_file);
        $width = $imgsize[0];
        $height = $imgsize[1];
        $mime = $imgsize['mime'];
     
        switch($mime){
            case 'image/gif':
                $image_create = "imagecreatefromgif";
                $image = "imagegif";
                break;
     
            case 'image/png':
                $image_create = "imagecreatefrompng";
                $image = "imagepng";
                $quality = 10;
                break;
     
            case 'image/jpeg':
                $image_create = "imagecreatefromjpeg";
                $image = "imagejpeg";
                $quality = 100;
                break;
     
            default:
                return false;
                break;
        }
         
        $dst_img = imagecreatetruecolor($max_width, $max_height);
        $src_img = $image_create($source_file);
         
        $width_new = $height * $max_width / $max_height;
        $height_new = $width * $max_height / $max_width;
        //if the new width is greater than the actual width of the image, then the height is too large and the rest cut off, or vice versa
        if($width_new > $width){
            //cut point by height
            $h_point = (($height - $height_new) / 2);
            //copy image
            imagecopyresampled($dst_img, $src_img, 0, 0, 0, $h_point, $max_width, $max_height, $width, $height_new);
        }else{
            //cut point by width
            $w_point = (($width - $width_new) / 2);
            imagecopyresampled($dst_img, $src_img, 0, 0, $w_point, 0, $max_width, $max_height, $width_new, $height);
        }
         
        $image($dst_img, $dst_dir, $quality);
     
        if($dst_img)imagedestroy($dst_img);
        if($src_img)imagedestroy($src_img);
    }      
?>

您可以使用此库:调整图像的大小/剪切图像

重要信息:要查看此函数的其他参数,您可能可以自定义图像的裁剪方式

诸如此类:

ImageProperties-properties=wait-flatternativeimage.getImageProperties(file.path);
File crappedfile=await flatternativeimage.cropImage(File.path,originX,originY,500500);

originX/originY:剪切的x/y位置。

您可以使用此库:调整图像大小/剪切图像

重要信息:要查看此函数的其他参数,您可能可以自定义图像的裁剪方式

诸如此类:

ImageProperties-properties=wait-flatternativeimage.getImageProperties(file.path);
File crappedfile=await flatternativeimage.cropImage(File.path,originX,originY,500500);

originX/originY:切割的x/y位置。

你知道我应该用什么来切割originX,originY,如果我想从正中裁剪的话?我想裁剪功能是用来从originX/originY切割图像的,宽度和高度都是一样的<代码>FlatterNativeImage.CompressionImage不工作?我不确定为什么要压缩图像进行裁剪?我猜我能找到这样的中心;int originX=properties.width~/2;int originY=properties.height~/2;但是我对传递给crop函数的参数有点困惑。我正在从互联网上截取一张图片进行裁剪,所以我有一个URL/文件路径,但不确定该用什么来制作文件图片;这是我到目前为止得到的;cropAvatar(File image,filepath)async{ImageProperties=await flatternativeimage.getImageProperties(filepath);int-originX=properties.width~/2;int-originY=properties.height~/2;File-cropedfile=await flatternativeimage.cropImage(filepath,originX,originY,500500);返回cropedfile;}我认为如果使用crop,它会从原始图像上切下一部分,失去一个好的部分,这就是为什么我认为你需要调整图像的大小。但是如果你只想剪切其中的一部分,originalX/Y是你想要剪切的初始点,可能是0。你知道我应该用什么来切割originalX,Original如果我想从中心精确地剪切它吗?我想裁剪函数是用来从originalX/Original切割图像的,具有这样的宽度和高度<代码>FlatterNativeImage.CompressionImage不工作?我不确定为什么要压缩图像进行裁剪?我猜我能找到这样的中心;int originX=properties.width~/2;int originY=properties.height~/2;但是我对传递给crop函数的参数有点困惑。我正在从互联网上截取一张图片进行裁剪,所以我有一个URL/文件路径,但不确定该用什么来制作文件图片;这是我到目前为止得到的;cropAvatar(File image,filepath)async{ImageProperties=await flatternativeimage.getImageProperties(filepath);int-originX=properties.width~/2;int-originY=properties.height~/2;File-cropedfile=await flatternativeimage.cropImage(filepath,originX,originY,500500);返回cropedfile;}我认为如果使用crop,它会从原始图像上切下一部分,失去一个好的部分,这就是为什么我认为你需要调整图像的大小。但是如果你只想切割一部分,原始X/Y是你想要切割的初始点,可能是0。