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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.