The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Image size
CodeKing
post Oct 7 2006, 02:56 PM
Post #1


Advanced Member
****

Group: Members
Posts: 175
Joined: 12-September 06
Member No.: 118



When somebody uploads an image, I want a thumbnail of it displayed. I figured I would have javascript read the location of the image, then resize it down to a thumbnail. I only problem is, how do you get the width and height of an image so I can shrink it without distortion. Also, how do you read the value of a file input field?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Oct 7 2006, 04:51 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,653
Joined: 10-August 06
Member No.: 7



If you specify only the image's WIDTH or HEIGHT the browser should calculate the missing one automatically.

To get the file INPUT field's value you might simply use onchange="this.value" but that only seems to work well in IE/win. Other browsers (and OS) probably get problems with their different file paths.

--------

The fundamental issue seems to be to let users see which image they've selected for upload. Since images can be previewed in Windows Explorer, why not let the user upload files through Explorer's FTP functionality instead of through a form? But maybe that creates other problems.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Sparkyg
post Oct 7 2006, 05:13 PM
Post #3


Member
***

Group: Members
Posts: 46
Joined: 29-September 06
From: Suffolk UK
Member No.: 270



Hi there

If you are using PHP it is fairly simple to resize an image using the GD library.

I can expand on this if required

cheers

Sparky

User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Oct 8 2006, 03:31 AM
Post #4


.
********

Group: WDG Moderators
Posts: 9,653
Joined: 10-August 06
Member No.: 7



PHP also contains the getimagesize() function. But if I understood the OP correctly, he wants to let users preview images before they are uploaded.

Another idea might be to offer an online preview, where the user has the chance of deleting his newly uploaded file.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Sparkyg
post Oct 8 2006, 04:52 AM
Post #5


Member
***

Group: Members
Posts: 46
Joined: 29-September 06
From: Suffolk UK
Member No.: 270



Yep your right christian, it was getting late for me smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
stjepan
post Oct 28 2006, 04:14 PM
Post #6


Serious Coder
*****

Group: Members
Posts: 329
Joined: 15-October 06
From: zagreb, croatia
Member No.: 445



QUOTE
...he wants to let users preview images before they are uploaded.


Why should one wanted to do that? There's View->Thumbnails in Windows...
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Oct 29 2006, 12:07 AM
Post #7


Jocular coder
********

Group: Members
Posts: 2,460
Joined: 31-August 06
Member No.: 43



QUOTE(CodeKing @ Oct 8 2006, 04:56 AM) *

When somebody uploads an image, I want a thumbnail of it displayed. I figured I would have javascript read the location of the image, then resize it down to a thumbnail. I only problem is, how do you get the width and height of an image so I can shrink it without distortion. Also, how do you read the value of a file input field?


Javascript has no access to the file system. Until the visitor commits to sending you the file, you can't see it, for obvious security reasons. Before the visitor sends it, it's up to the visitor to arrange whatever mechanism to preview the images to send. (Of course you could write a Doze application to do this and offer it for download if you wish.)

Once the file has been uploaded, it only makes sense to resize it on the server, and show a confirmation page with a thumbnail sized version. You need something like php and the gd library for this.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 18th April 2024 - 06:18 PM