Forum Moderators: open

Message Too Old, No Replies

resize photos from a form

how to use a value from a form

         

sanblasena

6:29 pm on Apr 19, 2006 (gmt 0)

10+ Year Member



Hi, I am doing an image upload. I have a form set up with type=file in to allow the user to select the photo they want to upload. I have also found a script which resizes photos in javascript - attached at bottom. My question is, how do I get the photo they selected to resize?

Thanks, Pat

Here is my form:
<form action="<?=$SCRIPT_NAME;?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000">

<p>Upload Image: <input type="file" name="imgfile" size="30" style="height: 24px"><br>
<font size="1">Click browse to upload a local file</font><br>

Use this as your header photo?<input type="radio" name="header" value="yes"><BR> <br>
<input type="submit" value="Upload Image">
</form>

Here is the Javascript I found.
<!-- THREE STEPS TO INSTALL AUTOMATIC IMAGE RESIZER:

1. Copy the coding into the HEAD of your HTML document
2. Add the onLoad event handler into the BODY tag
3. Put the last coding into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

<HEAD>

<style type="text/css">
<!--
.simple {
border: 1px solid #cccccc; padding: 5px; text-align: center
}
-->
</style>

<script type="text/javascript">
<!-- Begin
/* This script and many more are available free online at
The JavaScript Source! http://javascript.internet.com
Created by: Cat Arriola :: http://astrodiva.journalspace.com */

function fixImgs(whichId, maxW) {
var pix=document.getElementById(whichId).getElementsByTagName('img');
for (i=0; i<pix.length; i++) {
w=pix[i].width;
h=pix[i].height;
if (w > maxW) {
f=1-((w - maxW) / w);
pix[i].width=w * f;
pix[i].height=h * f;
}
}
}
//-->
</script>
</HEAD>

<!-- STEP TWO: Insert the onLoad event handler into your BODY tag -->

<BODY onload="fixImgs('photos', 108) /*('element ID', maximum width)*/">

<!-- STEP THREE: Copy this code into the BODY of your HTML document -->

<div align="center">
<table id="photos" cellspacing="2">
<tr>
<td class="simple"><img src="sample1.jpg" alt="photo 1"></td>
<td class="simple"><img src="sample2.jpg" alt="photo 2"></td>
<td class="simple"><img src="sample3.jpg" alt="photo 3"></td>
</tr>
<tr>
<td class="simple" colspan="3"><b>Live demo:</b> <input type="button" value="Make width 80 pixels" onclick="fixImgs('photos', 80)"></td></tr>
<tr>
<td align="center" colspan="3"><a style="font-size:12px; color:blue; text-decoration:none" href="http://astrodiva.journalspace.com/" target="offsite">C a t m a d e i t!</a></td></tr>
</table>
</div>

<p><center>
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

<!-- Script Size: 2.07 KB -->

[edited by: DrDoc at 5:21 pm (utc) on June 5, 2006]

da644

10:40 pm on Apr 19, 2006 (gmt 0)

10+ Year Member



Hi.

You can't resize the photo using JS, you will need to use a server tech. to do this. JS is not able to modify files on the users system, this would create a massive security hole. All the JS you have if doing is changing the width and height attributes of the <img> tag.

Kind regards,

Andrew
<snip>

[edited by: trillianjedi at 1:29 pm (utc) on April 20, 2006]
[edit reason] No sigs and please see TOS #13 [/edit]

sanblasena

12:18 pm on Apr 20, 2006 (gmt 0)

10+ Year Member



I have read that there are packages that resize the photos prior to uploading them. Any idea how this is done?

Pat

da644

2:19 pm on Apr 20, 2006 (gmt 0)

10+ Year Member



You could use Java, but it would be very difficult. What is the problem with resizing it server side?

Andrew.

[edited by: trillianjedi at 4:36 pm (utc) on April 20, 2006]
[edit reason] Please read our TOS re: sigs and URL's thanks. [/edit]

Trace

6:00 pm on Apr 20, 2006 (gmt 0)

10+ Year Member



Enter "iphoto-like" in Google.
Is that what you are looking for?

da644

8:01 pm on Apr 20, 2006 (gmt 0)

10+ Year Member



I will say it again, that is not actually resizing the image it is just adjusting the display width and height, from what I read from your message you actually want to resize the image file and not just change the display size of the image, maybe I'm wrong.

Andrew.

Inny

4:37 am on Apr 22, 2006 (gmt 0)

10+ Year Member



You might be intrested in this program you can integrate in your web page that does what you want :)

[imgfree.net...]

dsandall

6:16 pm on Apr 24, 2006 (gmt 0)

10+ Year Member



Hi,

As others have said you need to actually do the image manipulation server side. I have created a content management system for an art site that allows the artist to upload a photo, then using a DHTML tool, choose a crop area or resize attirbutes. These parameters are then passed back to a server side script (PHP) that uses the GD library to do further image manipulation.

Dwayne