2014-03-07 108 views
-1

的index.php使用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; 

    // 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()来保存文件的浏览器不预览图像。我想保存文件夹中的文件,但不显示在浏览器上。在浏览器中只显示此消息“图像调整大小成功”。

回答

3
<?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"; 
    ?> 
相关问题