【问题标题】:PHP image resize doesn't work as I wantPHP图像调整大小不能按我的意愿工作
【发布时间】:2017-01-19 17:01:16
【问题描述】:

我在简单的基本 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>');

问题是在网络中我从来没有收到“resize ok”,出了点问题..

顺序是否正确?

【问题讨论】:

  • 使用 error_log 将信息转储到错误日志中。这行不通
  • 您的图片是否成功调整大小?

标签: javascript php image resize


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-26
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多