create image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpoverso
Forum Newbie
Posts: 3
Joined: Mon May 30, 2005 6:37 am

create image

Post 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
phpoverso
Forum Newbie
Posts: 3
Joined: Mon May 30, 2005 6:37 am

Post by phpoverso »

User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
phpoverso
Forum Newbie
Posts: 3
Joined: Mon May 30, 2005 6:37 am

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
andrei.mita
Forum Commoner
Posts: 65
Joined: Sun May 08, 2005 4:06 am
Location: Barlad/Romania

Post 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';
AlexB
Forum Newbie
Posts: 6
Joined: Mon Apr 18, 2005 5:36 am
Location: Peterborough, UK

Post by AlexB »

Here

Or here

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