November 16th, 2000, 02:37 PM
I am currently in the process of building a smaller internet community, where people can register a user, and interact with each other in different ways.
I will let the users upload a user picture, which will be displayed on their personal page. Now, the problem I see is that some people have the habit of uploading huge pics, both pixel- and sizewise.
So my question is: is there a way I can automate the process of resizing a picture at the same time the user uploads it? I want it to have a width of X, but the height doesn't matter, but it should be proportional with the width when it is resized, so it doesn't become distorted.
Is there any way I can do this using PHP?
November 17th, 2000, 02:26 AM
there is a function named
read the manual of PHP, and you shd find something useful
November 17th, 2000, 06:24 AM
Thanks for the URL. It would have been most helpful if the PHP build my webhotel has installed, supported the resizing of JPEGs. Which it at this point does not, only GIFs...
November 17th, 2000, 11:28 AM
There is alternative solution, not exactly the "greatest" method.. but a possiblity.
You could use the "getImageSize()" function, to obtain the physical size (HxW) of the uploaded image.
At the point where the user uploads, you could check the image specs, to determine if it meets you site requirements.
The getImageSize() function works on GIF, JPG, PNG, and SWF imagery.
it returns an array, which includes:
Type: 1 = GIF, 2 = JPG, 3 = PNG and 4 = SWF
and height=x width=x
Used in conjunction with the MAX_FILE_SIZE
field, you can restrict image uploads.
In short, you wouldn't need to re-size a users uploaded image, you just simply restrict what can be uploaded.
Additionally you can ensure that users only upload images of a specific MIME type...
the enctype="multipart/form-data" attribute of the form field returns some very useful information about the file being uploaded.