PHP图像调整大小不能按我的意愿工作

时间:2016-09-12 09:29:43

标签: javascript php image resize

我在简单的基本PHP图像调整大小时遇到​​了问题。

我使用AJAX调用在POST中传递我的图像..

这是我的PHP代码:

//resize original image
            switch ($type) {
                case "desktop":
                    $width = 1920;
                    $height = 1080;
                break;

                case "mobile":
                        $width = 640;
                        $height = 1080;
                    break;
            }

                print_r("start resize");
                print_r('<br>');

                $size = getimagesize($url);
                $img_origX = imagesx($img_orig);
                $img_origY = imagesy($img_orig);
                //height (Auto calculate)
                //$height = round($width*$size[1]/$size[0]);
                $img = imagecreatetruecolor($width, $height);
                imagecopyresampled($img, $img_orig, 0, 0, 0, 0, $width, $height, $img_origX, $img_origY);

                // Output
                header('Content-type: image/jpg');
                imagejpeg($img , "thumbnail.jpg");

                $imageData = fopen("thumbnail.jpg", "r");

                print_r("resize ok");
                print_r('<br>');

问题是在网络中我从来没有收到&#34;调整大小确定&#34;出现问题..

序列是否正确?

1 个答案:

答案 0 :(得分:0)

删除print_r,当您输出图像时,它应该只包含图像的数据。 如果您只想输出图像,则imagejpeg只需要一个参数:imagejpeg($img); 为什么要打开文件$imageData = fopen("thumbnail.jpg", "r");?这不是输出图像所必需的

相关问题