Morning :o)
This is what I am using
--------------- SNIP ----------------
<?php
// The file
$filename = $_GET['filename'];
$file = $_GET['filename'];
$target_path = "../_images/news/";
$filename = $target_path.$filename;
// Set a maximum height and width
$width = 250;
$height = 250;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$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($filename);
$dest_path = "../_images/news/";
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
$width_orig, $height_orig);
$dest_file = $dest_path."thumb_".$file;
// Output
imagejpeg($image_p, $dest_file, 100);
?>
------------- SNAP ---------------
If I read it now, I must admit that it might be hard to understand (even I
am having a hard time reading it... I guess there is some useless stuff in
there, too)... but I haven't had coffee yet, so I might be able to explain
that stuff to you a bot late. But maybe this code example does help you...
if not, please ask. :o) I will try my best then ... hopefully you just
needed the calculation part :oP
Cheerio mate
Chris
----- Original Message -----
From: "Humani Power" <jiuman@xxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>
Sent: Monday, June 04, 2007 8:44 AM
Subject: Making thumbs same size
Hey hi!!.
I have a few pages that uploads images to the apache server and makes a
registry on a mysql database. Everything is going well just for a few
details.
When I make the upload for an image, it creates me a thumb image, but not
as
I want. For example, if I have an image that its of 2000 x 2000 px, the
thumb created is 200 x 200, If I upload another with 300x300 px, my thumb
will be 30x30 px, making look the gallery pretty bad. The only thing that
I
need is that all my thumbs were on the same size.
I've tried to modify the thumb width and height size, but doesnt work..
Probably I am not undersatnding hoy to use the resampling() tool.
here is my code.
<?php
include("connection.php");
//make variables avaliable
$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_tempname = $_FILES['image_filename']['name'];
$image_date = date($_POST['image_date']);
$today= date("Y-m-d");
//upload image and check for image type
$ImageDir="/var/www/apache2-default/images/";
$Imagethumb=$ImageDir."thumbs/";
$ImageName=$ImageDir . $image_tempname;
if (move_uploaded_file($_FILES['image_filename']['tmp_name'],
$ImageName)) {
//get info about the image being uploaded
list($width, $height, $type, $attr)= getimagesize($ImageName);
//insert info into the table
$insert= "insert into rsiis_images
(image_caption,image_username,image_date,image_date_upload)
values
('$image_caption','$image_username','$image_date','$today')";
$insertresults=mysql_query($insert)
or die(mysql_error());
$lastpicid=mysql_insert_id();
$newfilename=$ImageDir . $lastpicid .".jpg";
if($type==2){
rename($ImageName, $newfilename);
} else {
if ($type==1){
$image_old=imagecreatefromgif($ImageName);
}elseif ($type==3){
$image_old=imagecreatefrompng($ImageName);
}
//"convert the image to JPG
$image_jpg=imagecreatetruecolor($width,$height);
imagecopyresampled($image_jpg,$image_old, 0, 0, 0, 0, $width,
$height,$width,$height);
imagejpeg($image_jpg,$newfilename);
imagedestroy($image_old);
imagedestroy($image_jpg);
}
$newthumbname=$Imagethumb.$lastpicid.".jpg";
//get dimensions of the thumbnail
$thumb_width=$width*0.10;
$thumb_height=$height*.10;
//Create thumbnail
$largeimage=imagecreatefromjpeg($newfilename);
$thumb=imagecreatetruecolor($thumb_width,$thumb_height);
imagecopy($thumb, $largeimage, 0, 0, 0, 0,$width,$height);
imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0,
$thumb_width,$thumb_height,$width,$height);
imagejpeg($thumb,$newthumbname);
imagedestroy($largeimage);
imagedestroy($thumb);
$url="location:showimage.php?id=".$lastpicid;
header($url);
}
?>
thanks for your help
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php