A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearTake image input from folder and after resizing store it to a output folder - page 1
User InfoPosts
Take image input from folder and after resizing store it to a output folder#1
I need to take sequence of images as input from a folder and after resizing, the resized image should be stored on an output folder. I wrote code. But in my code after resizing image, output folder only has a black image.

To debug this code please create input & output folder and put some gif image on input folder and see the output on output folder. Please help.

<?php
$dir = opendir("input/");
$i = 0;
while ($imgfile = readdir($dir))
{
if ($imgfile != "." && $imgfile != "..")
{
$imgarray[$i] = $imgfile;
$newwidth = 240; //new width
$newheight = 320; //new height
$uploadedfile = $imgarray[$i];
$src = imagecreatefromgif($uploadedfile);
list($width, $height) = getimagesize($uploadedfile);
$tmp = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$filename = "output/" . $imgarray[$i];
imagegif($tmp, $filename, 100);
imagedestroy($src);
imagedestroy($tmp);
$i++;
}
}
closedir($dir);
?>

posted date: 2009-04-06 19:42:00


Re: Take image input from folder and after resizing store it to a output folder#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-06 19:42:01


Re: Take image input from folder and after resizing store it to a output folder#3
Your error is in this line:$uploadedfile = $imgarray[$i];Your images are in the input folder, but this is setting the variable to just the image name, so when you try calling imagecreatefromgif and getimagesize it is not finding an image, resulting in the black output you are getting. To fix, just add the correct directory before the name:$uploadedfile = "input/" . $imgarray[$i];Tested with this change and it works.As a side note, I was able to quickly find what was wrong with your code by having error_reporting on:error_reporting(E_ALL);ini_set((display_errors(, 1);By doing this, you will get warning messages and such that you may not see otherwise. These can be the difference between a quick fix and tearing your hair out for hours. Use it when you are debugging.

posted date: 2009-04-06 19:53:00


Re: Take image input from folder and after resizing store it to a output folder#4
OH, GREAT. It's working fine.Thanks bro.Thanks a lot.

posted date: 2009-04-06 20:09:00


Re: Take image input from folder and after resizing store it to a output folder#5
can u pls help me to use: error_reporting(E_ALL); ini_set('display_errors', 1); How I use it or add the code on which portion? i don’t use it before.

posted date: 2009-04-06 20:12:00


Re: Take image input from folder and after resizing store it to a output folder#6
You would add the code at the very top of your script. You could also modify your php.ini so that by default this is the behavior (as I believe it is) and then modify it on the top so that it is not when you are in production.

posted date: 2009-04-06 20:16:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.