繁体   English   中英

使用imagejpeg()保存到文件夹,但不会在浏览器中预览图像

[英]Using imagejpeg() save to folder but doesn't preview image on the browser

Index.php

<?php

    error_reporting(E_ALL);
    // File and new size
    //the original image has 800x600
    $filename = 'images/lazy1.jpg';
    //the resize will be a percent of the original size
    $percent = 0.5;

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

    // Get new sizes
    list($width, $height) = getimagesize($filename);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;

    // Load
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);

    // Resize
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    // Output and free memory
    //the resized image will be 400x300
    imagejpeg($thumb, "raj.jpg", 100);
    imagedestroy($thumb);
echo "Image Resize Successfully";
    ?>

我正在使用imagejpeg()保存文件。 我想将文件保存在文件夹中,但不显示在浏览器上。 在浏览器中仅显示此消息“图像调整大小成功”。

<?php

    error_reporting(E_ALL);
    // File and new size
    //the original image has 800x600
    $filename = 'images/lazy1.jpg';
    //the resize will be a percent of the original size
    $percent = 0.5;

    //Removed lines here

    // Get new sizes
    list($width, $height) = getimagesize($filename);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;

    // Load
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);

    // Resize
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    // Output and free memory
    //the resized image will be 400x300
    imagejpeg($thumb, "raj.jpg", 100);
    imagedestroy($thumb);
    echo "Image Resize Successfully";
    ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM