Jump to content


Photo

HuH ! Wierd Problem


  • Please log in to reply
No replies to this topic

#1 jaymc

jaymc
  • Members
  • PipPipPip
  • Advanced Member
  • 1,521 posts
  • LocationLiverpool

Posted 19 September 2006 - 04:08 PM

This script is supposed to read a directory full of images, manipulate them and then save them into another DIR

It is working, but, for some reason its only working for the last image of the Loop

Here is the code, see if you can see the problem

<?
$opendir = opendir("pics");

$c=1;
while ($readdir = readdir($opendir)){



	// Get new sizes
	list($newwidth, $newheight) = getimagesize($readdir);


	// Load
	$source = imagecreatefromjpeg($readdir);
	$max_width = 500;
	$max_height = 700;
	$origwidth = imagesx($source);
        $origheight = imagesy($source);

/*	if (imagesx($source) > $max_width || imagesy($source) > $max_height) {

      if ($max_height / $origheight < $max_width / $origwidth) { $scale = $max_height / $origheight; }
      if ($max_width / $origwidth < $max_height / $origheight) { $scale = $max_width / $origwidth; }
        $height = $scale * $origheight;
        $width = $scale * $origwidth;
	}

	else {
*/
	$width = $origwidth;
	$height = $origheight;



	$thumb = imagecreatetruecolor($width, $height);

	// Resize
	imagecopyresampled ($thumb, $source, 0, 0, 0, 0, $width, $height, $origwidth, $origheight);


	// Output
	
	imagejpeg($thumb,"userimages/$readdir");

	echo "$c - $readdir<BR>";
	$c++;
}
?>

I would love to change the world, but they won't give me the source code

SEO Agency




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users