jamesl Posted January 13, 2007 Share Posted January 13, 2007 I'm having a small ordeal with a site and people uploading large images (Often over 1MB). I can't rely on client side size restrictions, so that leaves me with two choices... to recompress into JPEG before sending to the client, or compressing and resizing on upload. I know it's possible, but I don't know how (Probably a rewrite rule), but I've seen sites that when an image is loaded, it instead takes you to a page which shows the image along with copyright information, a banner, the whatnot. Though, this would make things easier, I'd rather compress the files on upload. What would be best and how would I do it? Link to comment https://forums.phpfreaks.com/topic/34023-dynamic-images-serverside-jpeg/ Share on other sites More sharing options...
redbullmarky Posted January 13, 2007 Share Posted January 13, 2007 do you mean like a thumbnail, just a bigger version? Link to comment https://forums.phpfreaks.com/topic/34023-dynamic-images-serverside-jpeg/#findComment-159929 Share on other sites More sharing options...
jamesl Posted January 13, 2007 Author Share Posted January 13, 2007 Well I'd like to be able to do a thumbnail version, the main concern is people uploading large, uncompressed files, which get used for the MySpace equivalent of a display pic. When you have 10 1.5MB pictures on a page when they are being shrunk in HTML, it kind of causes... lag? Haha. Link to comment https://forums.phpfreaks.com/topic/34023-dynamic-images-serverside-jpeg/#findComment-159935 Share on other sites More sharing options...
redbullmarky Posted January 13, 2007 Share Posted January 13, 2007 ok, might be worth taking a look for thumbnail scripts anyway, but generally it involves [url=http://uk.php.net/gd]GD library[/url] to open, resize and display the smaller version. What its ability is to handle HUGE images is, I couldnt tell you... Link to comment https://forums.phpfreaks.com/topic/34023-dynamic-images-serverside-jpeg/#findComment-159944 Share on other sites More sharing options...
jamesl Posted January 13, 2007 Author Share Posted January 13, 2007 Jesus, das alot of stars... anyway, yeah, I figured I could just use the GD Library... Can you scale proportionally using the library? Seeing as I don't want images being square if they are rectangular. Link to comment https://forums.phpfreaks.com/topic/34023-dynamic-images-serverside-jpeg/#findComment-159945 Share on other sites More sharing options...
redbullmarky Posted January 13, 2007 Share Posted January 13, 2007 yeah - generally, to keep the quality, the function you're after is [url=http://www.php.net/imagecopyresampled]imagecopyresampled[/url]. it takes box coordinates of the source, box coordinates for the destnation, and voila.the working out comes seperately, but generally follows something like this:[code]<?php$filename = "test.jpg";$w = 200; // max width$h = 200; // max height//first open the file$im = imagecreatefromjpeg($filename);// get its width/height$sx = imagesx($im);$sy = imagesy($im);// work out the scale. $w would be initially set to the max width, $h to the max height$scale = min($w/$sx, $h/$sy);// send the necessary headers to the browser:header("Content-type: image/jpeg");// scale < 1 means it needs resizing as too bigif ($scale<1){ // work out the new width/height $newwidth = $scale * $sx; $newheight = $scale * $sy; // create a 'canvas' for it $im2 = imagecreatetruecolor($newwidth, $newheight); // do the copying and send to browser imagecopyresampled($im2, $im, 0, 0, 0, 0, $newwidth, $newheight, $sx, $sy); imagejpeg($im2); // clean up imagedestroy($im); imagedestroy($im2);}else{ imagejpeg($im); imagedestroy($im);}?>[/code] Link to comment https://forums.phpfreaks.com/topic/34023-dynamic-images-serverside-jpeg/#findComment-159948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.