Jump to content

HuH ! Wierd Problem


jaymc

Recommended Posts

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

[code]<?
$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++;
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/21294-huh-wierd-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.