简体   繁体   中英

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";
    ?>

I am using imagejpeg() to save file. i want save file in folder but not show on browser. in browser only show this message "Image Resize successfully".

<?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";
    ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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