GetDotted Domains

Viewing Thread:
"I'm still having trouble with PHP image functions."

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Mon 23/05/05 at 13:51
Regular
"Pouch Ape"
Posts: 14,499
I've never been able to get these to work:

$img_file = "sourceimage.jpg";

header("Content-type: image/jpeg");
$width = 180;
list($width_orig, $height_orig) = getimagesize($img_file);
print("$width_orig, $height_orig

");
$height = (int) (($width / $width_orig) * $height_orig);

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

imagejpeg($image_p, $img_file, 100);
imagedestroy($img_file);

Lifted mostly from PHP.net. Am I supposed to make this in a seperate file, then use it with HTML image tags? Had a look around the web, but couldn't find anything helpful. There's no apparent output, and my GD build is ok.
Mon 23/05/05 at 17:12
Regular
"Pouch Ape"
Posts: 14,499
I shouted out about 6 months ago, more than once, then left it.

This has made my day though.
Mon 23/05/05 at 17:11
Regular
"NULL"
Posts: 1,384
Ya shoulda shouted earlier - I've just made a gallery site using these exact functions. I'd have emailed you my code!
Mon 23/05/05 at 15:37
Regular
"Pouch Ape"
Posts: 14,499
Help yourself mate, I got it mostly from php.net

Really bloomin' useful, wish I'd sorted it out sooner! (by that I mean "wish I'd got Garin to sort it out sooner")
Mon 23/05/05 at 15:34
Regular
Posts: 4,279
You don't mind me lifting this code at some stage do you m_m. Obviously it wont be exactly the same but I need something similar for a gallery.
Mon 23/05/05 at 15:31
Regular
"Pouch Ape"
Posts: 14,499
OK, cheers for the help Garin, I can't begin to tell you how many sites this is going to help me out on!

You, sire, are a genius.

EDIT: Yeah I did a quick test, uploaded a 0.5Mb file, thumbnailed it as a 27k file. Supoib.
Mon 23/05/05 at 15:30
Regular
"Devil in disguise"
Posts: 3,151
monkey_man wrote:
> One more thing: I'm assuming that if I upload a large image, this
> technique is to dynamically create a thumbnail of small filesize? I
> know it's obvious, but just making sure it doesn't load the entire
> image first, then resize it...

Yes, the image resizing is being done on the server by PHP, which outputs a smaller image that the browser downloads.
If you're going to use this alot, you'd be advised to look at doing the resizing once and writing out file, rather than doing it on the fly everytime though.
Mon 23/05/05 at 15:13
Regular
"Pouch Ape"
Posts: 14,499
EDIT: Aha - the header was in the wrong place, d'oh!

$img_dir = "../images/products/image_";
$img_format = ".jpg";
$img_file = "$img_dir$img_id$img_format";
$width = 180;

header("Content-type: image/jpeg");
list($width_orig, $height_orig) = getimagesize($img_file);
$height = (int) (($width / $width_orig) * $height_orig);

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

imagejpeg($image_p, null, 100);
imagedestroy($image_p);

Super.

One more thing: I'm assuming that if I upload a large image, this technique is to dynamically create a thumbnail of small filesize? I know it's obvious, but just making sure it doesn't load the entire image first, then resize it...
Mon 23/05/05 at 14:48
Regular
"Pouch Ape"
Posts: 14,499
Haha, ok. Still not working. Also, am I destroying the right image? Should that be image_p too?

EDIT: OK, this is what I have in the load_image.php file:


header("Content-type: image/jpeg");
$img_dir = "../images/products/image_";
$img_format = ".jpg";
$img_file = "$img_dir$img_id$img_format";
$width = 180;
list($width_orig, $height_orig) = getimagesize($img_file);
$height = (int) (($width / $width_orig) * $height_orig);

$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($img_file);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

imagejpeg($image_p, 100);
imagedestroy($image_p);

?>

What HTML do I need to put in? ?
Mon 23/05/05 at 14:47
Regular
"Devil in disguise"
Posts: 3,151
monkey_man wrote:
> So I won't be able to set the quality?

You can if you like. :)

imagejeg($image_p,100);
Mon 23/05/05 at 14:35
Regular
"Pouch Ape"
Posts: 14,499
Garin wrote:
> should be....
>
> imagejeg($image_p);

So I won't be able to set the quality?

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Easy and free service!
I think it's fab that you provide an easy-to-follow service, and even better that it's free...!
Cerrie
Just a quick note to say thanks for a very good service ... in fact excellent service..
I am very happy with your customer service and speed and quality of my broadband connection .. keep up the good work . and a good new year to all of you at freeola.
Matthew Bradley

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.