English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

My site, so for, is set up where people can enter their url for an image into a form, then the form sends the url to the database. then I have another php program that access the url and displays the picture. I was wondering if there is a way I can keep people from submitting links to photos that are too big. I've tried the resize command, but it stretchs some of the photos that are smaller. Any advice?

2006-09-17 09:28:52 · 2 answers · asked by detroitkid17 2 in Computers & Internet Programming & Design

2 answers

Here's what I do:

Use the GD commands to create an image resource from the URL. Then use the images_x() and images_y() functions to get the image size. Use the imagecopyresized() function ONLY IF the image is over a certain dimensional threshold.

Using simple mathematical ratios and the max() function to get the largest over-the-limit dimension, you can keep the image proportional. Then just use the imagegif(), imagepng(), imagejpeg(), etc. functions with an argument to upload the resized image, and use the uploaded image's URL instead of the original URL.

If no resizing needs to take place, then just use the original image URL and don't bother wasting space with unnecessarily uploaded images.

GD functions come in handy... a lot....

-IMP ;) :)

2006-09-17 10:56:20 · answer #1 · answered by icemetalpunk 5 · 0 1

You could open a connection to the url from PHP and then read in the binary data of the picture. Store it in an image format and check the size on what they submitted. You could also just allow them to upload their own pictures to your server, but impose a size limit on them so that they can't upload large graphics.

Check out the fopen function in the manual. I have added the link to it below. There it will tell you how to open the remote file using the binary flag "b" and once you have it, you can perform all sorts of file operations like size, dimensions etc on it.

Hope this helps you!

2006-09-17 11:01:12 · answer #2 · answered by Martyr2 7 · 0 0

fedest.com, questions and answers