All pastes #458421 Raw Edit

Miscellany

public text v1 · immutable
#458421 ·published 2007-04-25 21:41 UTC
rendered paste body
<?php
# Load Image
$img = open_image($_GET['img']);
if ($img === false) { die ('Unable to open image'); }
# Get Original Sizes
$width = imagesx($image);
$height = imagesy($image);
# Set Size
if($width > $height) {
	$new_width = 128;
	# Get Percentage
	$percentage = ($new_width / $width) * 100;
	# Calculate New Height
	$new_height = $height / $percentage;
} elseif($height > $width) {
	$new_height = 128;
	# Get Percentage
	$percentage = ($new_height / $new_height) * 100;
	# Calculate New Height
	$new_width = $width / $new_width;
} else {
	$new_width = 128;
	$new_height = 128;
}
# Create Image Base
$new_img = imagecreatetruecolor($new_width, $new_height);
# Resample The Image
imagecopyresampled($new_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
# Set Header Type
header('Content-type: image/jpeg');
# Display Resized Image
imagejpeg($new_img);
# End Script
die();
?>