簡體   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