|
 |
|
 |
03-06-2005, 03:28 PM
|
#1 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
Resizing images on the fly using GD?
I've spent several hours searching including last night looking for a solution to this. I've called an array of images to be displayed on my home page, but they're so big outright I had to resize them.
Well, the pics now look like s#%t since the html doesn't maintain the correct aspect ratio when altering height/width dimensions. Is there a way I can incorporate a string or something for gd resizing to the output images in the array?
|
|
|
03-06-2005, 11:37 PM
|
#2 (permalink)
|
|
Newbie
Join Date: Jun 2002
Location: Denmark
Posts: 1,710
|
Why not use the php Image library functions.
|
|
|
03-07-2005, 03:09 AM
|
#3 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
Thanks for the reply : )
Ok, doesn't really matter which as long as the aspect ratio of the image is maintained when resized.. I have no library preference at the moment. I'm still confused though lol. The images I have on display are called from a members table by sql array. The image root in the table is specific and retrieved to the userid it belongs to. I'm checking this link out and feeling mighty stupid,  It's just not getting through for some reason.
How do I get this to work when the 'img src' I'm using for output is of an array and not an individual file path?
Since I'm asking questions and creating a seperate thread would be too much imo, how on earth do I rid my text of unwanted slashes? You know, I'm instead of I\m, etc.
|
|
|
03-07-2005, 06:19 AM
|
#4 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,487
|
are you sure you need to resize them? or would just modifying the width and height attributes of the img tag work if the aspect was fine.
for example, i am pretty sure you can declare just one of the attributes and the other will scale with the aspect.
i.e. if you have an image that is 1024x768, .. you could use <img src=images/someimage.jpg width=800> and it should display a height of 600. ( i think )
if not, then it is definately time to look at the image library. if this is the case, then my question would be, how do the images get there? is there an upload script? if so, then you could add a function to resize the image at the time of upload.
if not, then it will be more demanding on the server since you will have to check for the image size, and then write logic to resize if the image is over the threshold.
__________________
Mike
|
|
|
03-07-2005, 06:52 AM
|
#5 (permalink)
|
|
Java fanboy
Join Date: Aug 2003
Posts: 1,161
|
Quote:
|
Originally Posted by sde
are you sure you need to resize them? or would just modifying the width and height attributes of the img tag work if the aspect was fine.
for example, i am pretty sure you can declare just one of the attributes and the other will scale with the aspect.
i.e. if you have an image that is 1024x768, .. you could use <img src=images/someimage.jpg width=800> and it should display a height of 600. ( i think )
|
Good god, no. Don't even suggest that, lest some newbie pick up on it and decide that it's a good way to shrink all the images displayed on their site. The original (usually huge) file is transfered, and the image is shrunk by the client, not a good way to do things on the web.
|
|
|
03-07-2005, 06:54 AM
|
#6 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,487
|
 .. i do it on one site where most of the images are close, .. however i am linking to an external server for the images which i have absolutely no control over.
good point though, .. quite possibly very bad web design.
__________________
Mike
|
|
|
03-07-2005, 02:36 PM
|
#7 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
Yeah, just using the html to reduce image dimensions is bad business. It does look better just identifying the width but it doesn't have that smooth look the image library resizing returns, the details look squished distorting stuff like facial features somewhat.
img syntax looks like this at the moment: (using print to follow up the fetch array btw.) 'img src=$root_url$sql_array->mem_pic
##what it returns##
'img src=http://blah/members/(image matching user_id & mem_pic within members table .jpg)'
-The folder for images in general is members.
-User specific image root defined under mem_pic: '/members/mypic.jpg'
I can pull off resizing an individual image properly using php library functions since all that has to be done is fill in the root to the image and much of the rest is copy and paste..but how do I apply it to the above array?
|
|
|
03-07-2005, 02:44 PM
|
#8 (permalink)
|
|
Moderator
Join Date: May 2002
Location: us.ca
Posts: 4,487
|
can't you write a seperate script to just loop through all the images and resize them?
then, you can either verify image size at the point of upload and just give an error of "this image is too large" .. or resize on upload.
__________________
Mike
|
|
|
03-08-2005, 05:44 AM
|
#9 (permalink)
|
|
Code Monkey
Join Date: Feb 2005
Posts: 64
|
That's still out of my reach. If I knew how to script this I would've done it  . I'm trying to learn from the posted scripts out there, but none of them apply to an array of images on the fly so I wouldn't know what to change/add even by trial and error (a real pitfall to learning php as you go with no schooling/A-Z training). It would be ideal if I just had the image directory to define and the reduce size function work with any file with a jpg extension.
Ultimately, I'd only have to add a width=$shrink to the img array and I'd be done with this. At least, that's how I imagine it.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 05:05 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|