image resize problem

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
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

image resize problem

Post by itsmani1 »

Code: Select all

$image = &quote;test.jpg&quote;;
$width = &quote;120&quote;;
$height = &quote;120&quote;;
function ResizeImage($image ,$width ,$height) 
{ 
//image resizer by myscripting 
//get the size of the original 
$size = GetImageSize($image); 
//divide the width / height percentage by 100 
$new_width = 100 / $width; 
$new_height = 100 / $height; 
//store the resized dimensions in a variable 
$sizeh = $sizeї1]/ $new_height; 
$sizew= $sizeї0]/ $new_width; 
//display the new resized image 
$new_image = &quote;<img src = \&quote;$image\&quote; height=\&quote;$sizeh\&quote; width =\&quote;$sizew\&quote;>&quote;; 
echo $new_image; 
}

Code: Select all

require(&quote;file1.php&quote;); 
//this reduces the image 
ResizeImage(&quote;test.gif&quote;,50,50); 
echo &quote;<br>&quote;; 
//we can increase an image as well 
ResizeImage(&quote;test.gif&quote;,50,50);
--------------------------
now problem is this here i m giving height and width :)
now i want to mention one of both either height or width?
can i do tht?


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i don't quite follow what you are asking? could you try to reitterate?




(just for simplicity sakes, here is a pretty good discussion on resizing images)
viewtopic.php?t=18814
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

i want to create thumbnails ???
and can u tell me the script i placed in last post is ok ???
problem to me is this ::::
that script works fine for the images that are of same width and length:
but it does not work for images with different width length
like
Image1= 100*120
Image2 100*120
Image3 100*120
and a 4th image is

Image1= 155*150
in this case it changes its behaviour
Last edited by itsmani1 on Thu Mar 10, 2005 1:13 am, edited 1 time in total.
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

i don't know if you want to create thumbnails or not, only you know if you want to or not ;)

But as far as your code, the ideal behind it is correct it just doens't seem to be the *best* way to go about it imo... Thus why i gave you that URL...
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

Code: Select all

imagejpeg($img);	
}	
else	
{
what do u mean by this in ur code???
Post Reply