Forum Moderators: coopster
$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),
$_FILES['file']['size']));
$thumb = imagecreatefromstring($photo);
$width = imagesx($thumb);
$height = imagesy($thumb);
$thumb_height = 100;
$thumb_width = $width / $height * $thumb_height;
$thumbnail = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumbnail,$thumb,0,0,0,0,$width,$height,ImageSX($thumb),ImageSY($thumb));
$vehicle_id = $_POST['vehicle_id'];
$query = sprintf("INSERT INTO v_images(photo, file_ype, vehicle_id, thumbnail) VALUES
('%s', '%s', '%s', '%s')", $photo, $_FILES['file']['type'], $vehicle_id, $thumbnail);
Create a new image from the image stream in the string
$photo = addslashes(fread(fopen($_FILES['file']['tmp_name'], "r"),$_FILES['file']['size']));
function img_resize($photo_name, $from, $max, $to) {
$ext = strtolower(end(explode('.',$photo_name)));
if ($ext == 'jpg' ¦¦ $ext == 'jpeg') {
$im = imagecreatefromjpeg($from);
} else if ($ext == 'gif') {
$im = imagecreatefromgif($from);
} else if ($ext == 'png') {
$im = imagecreatefrompng($from);
} else {
return false;
}
$sx = imagesx($im);
$sy = imagesy($im);
$nx = $sx;
$ny = $sy;
if ($nx > $max) {
$nx = $max;
$ny = max(1, round($ny * ($nx / $sx)));
}
if ($ny > $max) {
$ny = $max;
$nx = max(1, round($nx * ($ny / $sy)));
}
$nm = imagecreatetruecolor($nx, $ny);
imagealphablending ($nm, false);
imagecopyresampled ($nm, $im, 0, 0, 0, 0, $nx, $ny, $sx, $sy);
if ($ext == 'jpg' ¦¦ $ext == 'jpeg') {
imagejpeg ($nm, $to);
} else if ($ext == 'gif') {
imagegif ($nm, $to);
} else if ($ext == 'png') {
imagesavealpha ($nm, true);
imagepng ($nm, $to);
} else {
return false;
}
}
$thumbnail = img_resize($_FILES['file']['size'], $_FILES['file']['tmp_name'], 200, 'resized.jpg');
$vehicle_id = $_POST['vehicle_id'];
$query = sprintf("INSERT INTO v_images(photo, file_ype, vehicle_id, thumbnail) VALUES
('%s', '%s', '%s', '%s')", $photo, $_FILES['file']['type'], $vehicle_id, $thumbnail);