spectacularstuff Posted July 12, 2008 Share Posted July 12, 2008 Notes I have the issue resolved with one image in GD and I could easily copy that code 5 or 6 times to get multiple images to output however I would like to do this a little easier but and running into a road block. This problem I am sure is due to my lack of experience in programming with GD. Issue I am attempting to use an array and a for statement to output multiple images in GD as is done with anything else I have worked with. When I attempt to run an array of images via a FOR loop I get no image and no multiple images. URL Broken Code URL: Spectacular Computer Repair OR http://67.199.62.141/test3.php whichever you prefer. Correct Code to OUTPUT 1 Image URL: Computer Repair Sarasota, Bradenton, Venice OR http://67.199.62.141/test2.php whichever you prefer. Broken Code <?php function open_image($file) { # JPEG: $im = @imagecreatefromjpeg($file); if ($im !== false) { return $im; } # GIF: $im = @imagecreatefromgif($file); if ($im !== false) { return $im; } # PNG: $im = @imagecreatefrompng($file); if ($im !== false) { return $im; } # GD File: $im = @imagecreatefromgd($file); if ($im !== false) { return $im; } # GD2 File: $im = @imagecreatefromgd2($file); if ($im !== false) { return $im; } # WBMP: $im = @imagecreatefromwbmp($file); if ($im !== false) { return $im; } # XBM: $im = @imagecreatefromxbm($file); if ($im !== false) { return $im; } # XPM: $im = @imagecreatefromxpm($file); if ($im !== false) { return $im; } # Try and load from string: $im = @imagecreatefromstring(file_get_contents($file)); if ($im !== false) { return $im; } return false; } header ('Content-Type: image/png'); // What type of image are we working with? I also need to learn how to output multiple headers if I am using different images. //$image = open_image('SCRFix-logo.png'); // Where is the image located? //Image array and their correct locations. $image = array("/images/scrfix-logo.png", "/images/shopping-cart.jpg", "/images/forums.jpg", "/images/sign-in.jpg", "/images/contactus.jpg", "/images/printer.jpg"); //Check to see if we can find the image if ($image === false) { die ('Unable to find image'); } for ($i = 1; $i < 6; $i++) { $image = open_image($image); imagepng($image); // Outputs to browser directly only once through GD Code however this doesn't return an image. } //imagejpeg($image); //Here for testing purposes because I have multiple different types of images, both png and jpg for quick loading. ?> Correct Code to OUTPUT 1 Image <?php function open_image($file) { # JPEG: $im = @imagecreatefromjpeg($file); if ($im !== false) { return $im; } # GIF: $im = @imagecreatefromgif($file); if ($im !== false) { return $im; } # PNG: $im = @imagecreatefrompng($file); if ($im !== false) { return $im; } # GD File: $im = @imagecreatefromgd($file); if ($im !== false) { return $im; } # GD2 File: $im = @imagecreatefromgd2($file); if ($im !== false) { return $im; } # WBMP: $im = @imagecreatefromwbmp($file); if ($im !== false) { return $im; } # XBM: $im = @imagecreatefromxbm($file); if ($im !== false) { return $im; } # XPM: $im = @imagecreatefromxpm($file); if ($im !== false) { return $im; } # Try and load from string: $im = @imagecreatefromstring(file_get_contents($file)); if ($im !== false) { return $im; } return false; } header ('Content-Type: image/png'); // What type of image are we working with? $image = open_image('SCRFix-logo.png'); // Where is the image located? what is the image named? Do not use a / in the beginning of the location ie. /images/SCRFix-Logo.png is a no no. Use images/SCRFix-logo.png //Check to see if we can find the image if ($image === false) { die ('Unable to find image'); } imagepng($image); ?> Any help would be appreciative. You can find all of the images I am working with here Image Locations http://67.199.62.141/images/scrfix-logo.png http://67.199.62.141/images/shopping-cart.jpg http://67.199.62.141/images/forums.jpg http://67.199.62.141/images/sign-in.jpg http://67.199.62.141/images/contactus.jpg http://67.199.62.141/images/printer.jpg Thanks, Wayne Link to comment https://forums.phpfreaks.com/topic/114427-multiple-image-output-in-gd-php/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.