All pastes #634841 Raw Edit

Unnamed

public text v1 · immutable
#634841 ·published 2007-07-26 18:10 UTC
rendered paste body
<?php
	$uploadfile = '/path/to/image.jpg';
        $t_newfilename = '/path/to/newimage.jpg
	// Set a maximum height and width
	$width = 125;
	$height = 125;

	// Not needed
	#header('Content-type: image/jpeg');

	// Get new dimensions
	list($width_orig, $height_orig) = getimagesize($uploadfile);

	$ratio_orig = $width_orig/$height_orig;

	if ($width/$height > $ratio_orig) {
	   $width = $height*$ratio_orig;
	} else {
	   $height = $width/$ratio_orig;
	}

	// Resample
	$image_p = imagecreatetruecolor($width, $height);
	$image = imagecreatefromjpeg($uploadfile);
	imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

	// Output
	if(imagejpeg($image_p, $t_newfilename, 100))
	{
	
		echo 'Thumbnail created successfully!' . "\n";
	
	}else{
	
		echo 'Could not create thumbnail, please contact support';
	}

	// end thumbnail
?>