writeImage()时的页面错误

I have script to resize my photo with Imagick and then save. Here is code to make thumbnail with thiumbnailImage();

<?php
  header('Content-type: image/jpeg');
  $image = new Imagick('test.jpg');
  $image->thumbnailImage(600, 0);
  echo $image;
?>

Exmaple -> Resize example just thumbnailImage();.

This works. But when i want to save it with writeImage();.

<?php
  header('Content-type: image/jpeg');
  $image = new Imagick('test.jpg');
  $image->readImage('test.jpg');
  $image->thumbnailImage(600, 0);
  $image->writeImage('test_resized.jpg');
?>

It display server error. Example -> Example resize with writeImage();

It seems you probably don't have write permission to that directory.. Set permission(CHMOD) to 777.

To debug the error, try this code:

<?php
  error_reporting(E_ALL);
  ini_set('display_errors', 1);
  // header('Content-type: image/jpeg');  // note this is commented
  $image = new Imagick('test.jpg');
  $image->readImage('test.jpg');
  $image->thumbnailImage(600, 0);
  $image->writeImage('test_resized.jpg');
?>

The reason for commenting out the header call is so that the browser doesn't try to display the page as an image and prevent you from viewing source or seeing error messages.

Problem solved. I didn't have permission to writeImage();