Page 1 of 1

create image

Posted: Mon May 30, 2005 6:45 am
by phpoverso
Hi friends..

I hope you will help me..

I want to upload pictures with PHP.
Size of pictures are not standard , I mean their size are different from each other.

But, I want to resize them.


I want to use a draft.
its size is 150x150

when I upload a pictures, I want to reach the middle picture..
for example,
its original size is 400x300

so, it must be lacoted in my draft(150x150)

But, I don't want deformation in pictures uploaded.

I mustn't use <img src=pic.gif width=150 height=150>

I must use PHP..

and I think, I could't tell what I want :(
because my English is bad.

thank you

Posted: Mon May 30, 2005 6:53 am
by phpoverso

Posted: Mon May 30, 2005 9:44 am
by pickle
Once you get the image uploaded, call getimagesize() on the file, and you'll have the dimensions. What you want to do is resize the largest dimension down to 150 px, then resize the shorter dimension by the same amount.

So, for example, if you have a picture 450 X 300 px, you want to resize the 450 down to 150 (33% or 0.33 of the original dimension). Then resize the 300px side that much, and you'll have your dimensions of 150 X 100px.

Posted: Mon May 30, 2005 10:21 am
by phpoverso
okay but I can't :)

do you know any sample code to do it ?

I tried some sample but I didn't get what I want

Posted: Mon May 30, 2005 11:03 am
by pickle
What do you mean you can't? Do a search (both in this forum and Google), for PHP thumbnail generation. A lot of the schemes just make the thumbnail a smaller image, without worrying about dimensions, but just do what I said in my earlier post, and you should be able to make it work.

Posted: Tue May 31, 2005 3:44 am
by andrei.mita
i had this exact problem today.
here is my code

Code: Select all

<?php
$photo = 'photos/'.$name.'_'.$sname.'.jpg';

echo "You are viewing photo: ".$photo;

list($width, $height) = getimagesize($photo);

echo "<br>Original size:";
echo "<br>Height: ".$height;
echo "<br>Width: ".$width;

if ($width > $height)
		{
		 echo '<br><br><img src="'.$photo.'" width="150" border="0" alt="">';
		}

elseif($height >= $weight)
      {
       echo '<br><br><img src="'.$photo.'" height="150" border="0" alt="">';
      }
?>
I think the script it's self explenatory, if you have problems using it just ask.
PS:
You have to set your own image path here:

Code: Select all

$photo = 'photos/'.$name.'_'.$sname.'.jpg';

Posted: Tue May 31, 2005 4:35 am
by AlexB
Here

Or here

( JAM | Removed the uk. part of the links. Always refer to php.net as http://php.net/function. )