Question:
PHP dynamic image resizing issue?
Nicholas
2010-09-12 14:32:12 UTC
I made a site that lets you upload images with a form. On a separate page people can view these images. Since most of the images are very huge as they came directly from a camera, I used the height and width attributes of the image tags to make them a smaller size. However the page takes a long time to load and scrolling is very choppy. The best thing to do would be to use PHP to dynamically resize the images before they are saved on the server. I used this code:

$smaller = imagecreatetruecolor(300, 250);
$original = imagecreatefromjpeg("../images/tmp/$t.jpg");
list($width, $height) = getimagesize("../images/tmp/$t.jpg");
imagecopyresized($smaller, $original, 0, 0, 0, 0, 300, 250, $width, $height);
imagejpeg($smaller, '../images/properties/' . time() . $_FILES['picture']['name'], 100);

but I get an error saying that the image I am trying to resize is too large. How make this resizing work?

(Yahoo Answers cut off one of the lines and added ... for some reason)
Three answers:
Dani
2010-09-15 18:53:18 UTC
try tucking it into bed at night-night time and kissing it on the screen. then, take it on a romantic walk on the beach. If that doesn't work, sit on it and fart. this causes the giga bites to mix and therefore causes it to break down it's restraning walls and work.
rasley
2016-10-04 14:07:59 UTC
with your photograph resizer you will could desire to place in writing to the itemizing the place the image is residing. If its permissions do no longer enable this, then you gets the errors you're turning out to be, wherein case you have another possibilities (in ordinary terms suitable if this function is new ... if it has worked contained in the previous this is a difficulty with only one corrupt photograph): a million) rearrange the situation the place all photographs stay to a itemizing the place you do no longer strategies there being a truly open permission regime (possibly no longer an spectacular thought so a techniques as protection is going) 2) use a itemizing with write permissions in ordinary terms for the writing place, yet pass away the interpreting place as is (this could have repercussions in different aspects of your internet site with admire to the place you seek for photographs) 3) possibly it is function to sit down down at the back of a password secure photograph itemizing (some cyber web servers enable password secure directories)
Sourcebits
2010-09-14 09:43:16 UTC
This scripts works fine, in local PC. Please check memory limit, upload size limit in PHP.INI file.

web hosting provider may help on this.




$smaller = imagecreatetruecolor(300,250);

$original = imagecreatefromjpeg("images.jpeg");

list($width,$height) = getimagesize("images.jpeg");

imagecopyresized($smaller, $original, 0, 0, 0, 0, 300, 250, $width, $height);

imagejpeg($smaller,time().'images2.jpg',100);

?>


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...