0

我一直在努力调整图像大小,但没有成功。我曾尝试使用 resize-class.php、php_image-magician.php 以及其他一些脚本,但每次都失败。我还在学习 php,所以也许有人可以对我的问题有所了解。这是我正在使用的代码

     // Loop $_FILES to test all files
                                foreach      ($_FILES['files']['name'] as $f => $name) {   
                                    $total++;   // Total count for images attempted to be uploaded
                                    if ($_FILES['files']['error'][$f] == 4) {
                                        $images .= "'', "; //Empty image if error found
                                        $descs .= "'', "; //Empty description if error      
                                        continue; // Skip file if any error found
                                    }          
                                    if ($_FILES['files']['error'][$f] == 0) {              
                                        if ($_FILES['files']['size'][$f] > $max_file_size) {
                                            $images .= "'', "; // Empty image on image error
                                            $descs .= "'', "; // Empty description on image error
                                            $errorCount++; //Erro counter
                                            $errorer .= " Image Too Large "; // Error feedback for user
                                            continue; // Skip large files
                                        }
                                        elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                                            $images .= "'', "; // Empty image if error found
                                            $descs .= "'', "; // Empty description if error found with image
                                            $errorCount++; //Erro counter
                                            $errorer .= " File must be jpg, png, jpeg, or gif "; //Error feedback for user
                                            continue; // Skip invalid file formats
                                        }
                                        else{ // No error found! Move uploaded files                
                                            $addName = str_replace(':', '', date('Y:m:d:h:i:s')); // Add to the name to make the image unique

                                            if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$addName.$name)) {
                                                $newName = $addName.$name;  
                                                $count++; // Number of successfully uploaded file
                                                $catch = "desc".$count; // Description of image
                                                $info = cleanInput(mysql_real_escape_string($_POST[$catch])); // clean input
                                                $descs .= "'$info', "; // Format it for database insert
                                                $images .= "'$newName', "; // Format image path for database

                                            }
                                        }
                                    }

                                } // End Foreach Loop

我在只需要一次上传的文件上使用http://www.w3bees.com/2013/03/resize-image-while-upload-using-php.html调整脚本大小,但每次我尝试将其添加到我下面的代码中时得到很多错误。我究竟做错了什么?

4

1 回答 1

0

下面的代码将帮助您调整图像的大小:

$image = new Imagick( $filename );
$imageprops = $image->getImageGeometry();
if ($imageprops['width'] <= 200 && $imageprops['height'] <= 200) {
    // don't upscale
} else {
    $image->resizeImage(200,200, imagick::FILTER_LANCZOS, 0.9, true);
}
于 2013-11-14T12:36:40.443 回答