调整图像大小 - 如果图片只显示一半

时间:2013-03-30 08:54:18

标签: php

这个脚本有些如何显示图像的一半而不是整个图像...我想弄清楚这里有什么问题

任何帮助,请

//文件

                        $ftimage = $_POST['feature_image'];

                        // maximum height 150 X width 150
                        $width = 150;
                        $height = 150;


                        // Dimensions Set
                        list($width_orig, $height_orig) = getimagesize($ftimage);

                        $ratio_orig = $width_orig/$height_orig;

                        if ($width/$height > $ratio_orig) {
                           $width = $height*$ratio_orig;
                        } else {
                           $height = $width/$ratio_orig;
                        }

                        // Resample
                        $image_p = imagecreatetruecolor($width, $height);
                        $image = imagecreatefromjpeg($ftimage);
                        imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

                        // Output
                        $image = imagejpeg($image_p, null, 100);
                        var_dump($image);

1 个答案:

答案 0 :(得分:-1)

尝试替换它

$ftimage = $_POST['feature_image'];

用它:

$ftimage = $_POST['feature_image']['tmp_name'];

或者,如果在您的POST请求中存储了远程图像的URL,请尝试以下操作:

$image = imagecreatefromstring(file_get_contents($ftimage));