Rubblewebs

THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.

I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.

IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.

Resize image on upload

This code displays a form that the user can use to resize an image on upload. When the form is submitted the image is uploaded to a tempory location where it is then resized and saved into the directory set in the code.

Note: If allowing user uploads the data submitted MUST be checked to stop people uploading code that can compramise the server.

		
<?php		
// If the form has been submitted do this
if ( isset( $_POST['Submit'] ) ){

// Temporary upload image name
$original_image = $_FILES['filename']['tmp_name'];

// Get the image dimensions
$size=GetImageSize( $original_image );

// Name to save the image as - in this case the same as the original
$new_image = $_FILES['filename']['name'];

// Maximum image width
$max_width = '200';

// Maximum image height
$max_height = '90';

// Resize the image and save

exec("convert $original_image -thumbnail $max_widthx$max_height $new_image");

echo "File uploaded<br>";

echo "<img src=\"".$new_image."\">";
}
else { ?>
<p>File to upload:</p>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data"> 
<input type="file" name="filename"  />
<input type="Submit" name="Submit" value="Submit" />
</form>
<?php } ?>