首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在php中调整大小后将图片保存到目录中?

如何在php中调整大小后将图片保存到目录中?
EN

Stack Overflow用户
提问于 2018-08-04 06:39:22
回答 1查看 982关注 0票数 1

我正在使用php中的GD库来调整上传的图片的大小,它工作得很好,但我就是想不出如何将调整后的图片保存到一个目录中。我该怎么做呢?我似乎没有收到任何错误。

代码语言:javascript
复制
   <?php
    // The file
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    $filename = 'test.jpg';
    $percent = 0.5;


    if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
            {

    $filename = $_FILES['photoimg']['tmp_name'];

    // Content type
    header('Content-Type: image/jpeg');

    // Get new dimensions
    list($width, $height) = getimagesize($filename);
    $new_width = $width * $percent;
    $new_height = $height * $percent;

    // Resample
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $image = imagecreatefromjpeg($filename);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    // Output
    imagejpeg($image_p, null, 100);

    //This is my attempt to save the image that does not work
 if (move_uploaded_file($image, "memberFiles/saved_image.jpg")) {
}
    }
    ?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-04 06:55:57

只需使用:

代码语言:javascript
复制
imagejpeg($image_p, 'some/other/existing/directory/result.jpg');
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51680873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档