Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-06-2005, 03:28 PM   #1 (permalink)
morpheuz
Code Monkey
 
Join Date: Feb 2005
Posts: 64
morpheuz is on a distinguished road
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?
morpheuz is offline   Reply With Quote
Old 03-06-2005, 11:37 PM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,710
redhead is on a distinguished road
Why not use the php Image library functions.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is online now   Reply With Quote
Old 03-07-2005, 03:09 AM   #3 (permalink)
morpheuz
Code Monkey
 
Join Date: Feb 2005
Posts: 64
morpheuz is on a distinguished road
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.
morpheuz is offline   Reply With Quote
Old 03-07-2005, 06:19 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 03-07-2005, 06:52 AM   #5 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
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.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 03-07-2005, 06:54 AM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
.. 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
sde is offline   Reply With Quote
Old 03-07-2005, 02:36 PM   #7 (permalink)
morpheuz
Code Monkey
 
Join Date: Feb 2005
Posts: 64
morpheuz is on a distinguished road
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?
morpheuz is offline   Reply With Quote
Old 03-07-2005, 02:44 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,487
sde is on a distinguished road
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
sde is offline   Reply With Quote
Old 03-08-2005, 05:44 AM   #9 (permalink)
morpheuz
Code Monkey
 
Join Date: Feb 2005
Posts: 64
morpheuz is on a distinguished road
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.
morpheuz is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
custom classloader or setting class path on the fly kitguys Java 0 03-04-2005 07:55 PM
Images freesoft_2000 Java 0 01-16-2005 10:59 AM
Possible to prevent images in a page from caching? Epsilon HTML, XML, Javascript, AJAX 2 09-06-2004 01:58 AM
New images reaffirm planet is lord of rings redhead Code Newbie News 0 07-05-2004 12:56 AM


All times are GMT -8. The time now is 05:05 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting