I apologize for second posting today It is my first day with the GD library and I hope that as soon I get over the initial difficulties, i can enter some code all on my own Previous help in this forum has been very valuable to me. I am trying to create thumbnail pictures according to this recipe: <? header('Content-Type: image/jpeg'); /* Code from: http://www.999tutorials.com/tutorial-create-thumbnail-with-php.html Quote: The function is not that hard to read. Simply copy the whole script and try it. Hope you get some use of this script and have fun with it and use it as much as you like!! */ function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth) { $srcImg = imagecreatefromjpeg("$imageDirectory/$imageName"); $origWidth = imagesx($srcImg); $origHeight = imagesy($srcImg); $ratio = $origWidth / $thumbWidth; $thumbHeight = $origHeight * $ratio; $thumbImg = imagecreate($thumbWidth, $thumbHeight); imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($thumbImg), imagesy($thumbImg)); imagejpeg($thumbImg, "$thumbDirectory/$imageName"); } createThumbnail("img", "IMG_001.jpg", "img/thumbs", 100); ?> Code (markup): A strangely looking thumbnail appears in the directory img/thumbs (100x1200 pix with thumbnail on top, original is 400 x 300). However, in the browser I cannot see any picture: Firefox browser (2.0.0.5) says: The image “http://127.0.0.1/~yngve/gd_test_03†cannot be displayed, because it contains errors. Code (markup): Internet Explorer browser (6.0) says nothing and displays a blank page. I would be very greatful for advice EDIT: What also riddles me is that the strangely looking thumbnail picture can be opened and seen diredctly with the browser, even though the script gives browser error as described above.
I think the problem has been solved. As I just start to learn PHP I don't want to jump to conclusions. However, as I understand the code provided by http://www.999tutorials.com/tutorial-create-thumbnail-with-php.html is wrong. Changing the code in two places (see below) will produce a normal thumbnail. (When entering my first post I thought the script should also output the image. This is wrong, the script does not output anything, it only places a thumbnail image in a separate directory.) Being a beginner I am not in a position to pass judgement, but as I understand it is remarkable that a respectable-looking web-site like http://www.999tutorials.com/tutorial-create-thumbnail-with-php.html puts two errors in its example code! Is this really so? <?php header('Content-type: image/jpeg'); /* Code from: http://www.999tutorials.com/tutorial-create-thumbnail-with-php.html quote: The function is not that hard to read. Simply copy the whole script and try it. Hope you get some use of this script and have fun with it and use it as much as you like!! */ function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth) { $srcImg = imagecreatefromjpeg("$imageDirectory/$imageName"); $origWidth = imagesx($srcImg); $origHeight = imagesy($srcImg); $ratio = $origWidth / $thumbWidth; [COLOR="Red"]// $thumbHeight = $origHeight * $ratio; CHANGED TO:[/COLOR] $thumbHeight = $origHeight / $ratio; $thumbImg = imagecreate($thumbWidth, $thumbHeight); [COLOR="Red"]// imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($thumbImg), imagesy($thumbImg)); CHANGED TO:[/COLOR] imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight); imagejpeg($thumbImg, "$thumbDirectory/$imageName"); } createThumbnail("img", "IMG_001.jpg", "img/thumbs", 100); ?> Code (markup):