Steffen Posted March 5, 2006 Share Posted March 5, 2006 I have found a tutorial to create thumbnails on the fly. This is the code:[code]# Constantsdefine(IMAGE_BASE, './images');define(MAX_WIDTH, 200);define(MAX_HEIGHT, 200);function show_thumbnail($image, $dirname){# Get image location$image_path = IMAGE_BASE . "/" . $dirname . "/" . $image;# Load image$img = null;$ext = strtolower(end(explode('.', $image)));if ($ext == 'jpg' || $ext == 'jpeg') { $img = @imagecreatefromjpeg($image_path);} else if ($ext == 'png') { $img = @imagecreatefrompng($image_path);# Only if your version of GD includes GIF support} else if ($ext == 'gif') { $img = @imagecreatefrompng($image_path);}# If an image was successfully loaded, test the image for sizeif ($img) { # Get image size and scale ratio $width = imagesx($img); $height = imagesy($img); $scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height); # If the image is larger than the max shrink it if ($scale < 1) { $new_width = floor($scale*$width); $new_height = floor($scale*$height); # Create a new temporary image $tmp_img = imagecreatetruecolor($new_width, $new_height); # Copy and resize old image into new image imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagedestroy($img); $img = $tmp_img; }}# Create error image if necessaryif (!$img) { $img = imagecreate(MAX_WIDTH, MAX_HEIGHT); imagecolorallocate($img,0,0,0); $c = imagecolorallocate($img,70,70,70); imageline($img,0,0,MAX_WIDTH,MAX_HEIGHT,$c2); imageline($img,MAX_WIDTH,0,0,MAX_HEIGHT,$c2);}# Display the imageheader("Content-type: image/jpeg");imagejpeg($img);}[/code]I have a page of large images, and i want to make thumbnails of them, without creating a new file. Just to decrease the file size.The problem is, when I try this for one image:For example:show_thumbnail("Foto 005.jpg", "test2");I get this output:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: Cannot modify header information - headers already sent by (output started at c:\program files\easyphp1-8\www\speelschare\index.php:23) in c:\program files\easyphp1-8\www\speelschare\sources\fotos\test2.php on line 59ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC $.' ",#(7),01444'9=82<.342ÿÛC 2!!22222222222222222222222222222222222222222222222222ÿÀÈÈ"ÿÄ ÿĵ}!1AQa"q2?‘¡#B±ÁRÑð$3br‚ %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ ÿĵw!1AQaq"2?B‘¡±Á #3RðbrÑ $4á%ñ&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz‚ƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊÒÓÔÕÖ×ØÙÚâãäåæçèéêòóôõö÷øùúÿÚ ?ùþŠ( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( Š( ÿÙ[/quote]I wanted to put the header on line 1, but the problem is that my page is not only one image, but also html and flash...Could anyone help me plz? Quote Link to comment Share on other sites More sharing options...
zq29 Posted March 5, 2006 Share Posted March 5, 2006 My suggestion would be to have your script in its own file, and to modify it to accept the image variables via $_GET[]. Then when you want a resized image, you use that file as the image source with the image details appended to the URL. i.e. <img src="imagesize.php?image=test.jpg" alt="Resized Image"/> Quote Link to comment Share on other sites More sharing options...
Steffen Posted March 5, 2006 Author Share Posted March 5, 2006 Hm, that seems a great idea!I will try this immediatly:)thx:) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.