Code: Select all
<?php
$connection = mysql_connect($host,$user,$password) #13
or die ("couldn't connect to server");
$db = mysql_select_db($database,$connection) #15
or die ("Couldn't select database");
$result2 = mysql_query("SELECT pic FROM pics WHERE person='Simulacra'");
for ($i=0; $i<mysql_num_rows($result2); $i++)
{
$pic2 = mysql_result($result2,($i));
# Constants
$mAX_WIDTH = 125;
$mAX_HEIGHT = 180;
# Get image location
$image_file = $pic2;
$image_path = $image_file;
# Load image
$img = null;
$ext = strtolower(end(explode('.', $image_path)));
if ($ext == 'jpg' || $ext == 'jpeg') {
$img = @imagecreatefromjpeg($image_path);
} else if ($ext == 'png') {
$img = @imagecreatefrompng($image_path);
# Only if your version of GD includes GIF support
} else if ($ext == 'gif') {
$img = @imagecreatefrompng($image_path);
}
# If an image was successfully loaded, test the image for size
if ($img) {
# Get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
$scale = min($mAX_WIDTH/$width, $mAX_HEIGHT/$height);
# If the image is larger than the max shrink it
if ($scale < 1) {
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
# Create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
# Copy and resize old image into new image
imagecopyresized($tmp_img, $img, 0, 0, 0, 0,
$new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
}
}
# Create error image if necessary
if (!$img) {
$img = imagecreate($mAX_WIDTH, $mAX_HEIGHT);
imagecolorallocate($img,0,0,0);
$c = imagecolorallocate($img,70,70,70);
imageline($img,0,0,$mAX_WIDTH,$mAX_HEIGHT,$c2);
imageline($img,$mAX_WIDTH,0,0,$mAX_HEIGHT,$c2);
}
# Display the image
header("Content-type: image/jpeg");
imagejpeg($img);
}
?>