裁剪图像,保存

时间:2012-02-15 15:15:48

标签: php gd

    $filename = '/home/hey/Desktop/images/oldImage.jpg';
    $percent = 0.5;

    // 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);
    file_put_contents("/home/hey/Desktop/images/oldImage.jpg", imagejpeg($image_p));

我只想稍微裁剪oldImage并再次保存。怎么了?感谢。

编辑:图片尚未创建。它会创建空白图像。

1 个答案:

答案 0 :(得分:3)

为什么不使用更简单的:

// Save the image as 'simpletext.jpg'
imagejpeg($image_p, 'simpletext.jpg');