2012-02-15 160 views
-7
$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并保存一遍。怎么了?谢谢。裁剪图像,保存它

编辑:图像只是没有创建。它创建空图像。

+6

你为什么不告诉我们,什么是错的,也许我们就可以帮你解决这个问题。图像未创建?图像奇怪吗?它会变成猫的照片吗?你会得到什么错误? – ceejayoz 2012-02-15 15:17:27

+0

是的,怎么了? – powtac 2012-02-15 15:17:48

+0

哦,对不起。我现在会更新。 – 2012-02-15 15:18:44

回答

3

为什么不使用更简单:

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

这不仅更简单,它也是唯一的方法来做到这一点:) – 2012-02-15 15:23:17