Jump to content

Archived

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

cmgmyr

Image Problems

Recommended Posts

ok I have a little photo gallery on a site. I made up a little bit of code that resizes the image if it is too big.

The script works fine when it's on my local computer, but when I upload it the script takes the image size of the image after the one it's supposed to, but outputs the image it is supposed to.

If I have image1 and image2, When I try and get the size of image1 it takes the size of image2, but still outputs image1...I don't get it...here is my code, please help if you can!

[code]    if (!isset($userid) or trim($userid)=='') {
      $gal = 1; }
    if (!isset($pic) or trim($pic)=='') {
      $pic = 1; }
    $dir= "custphotos/gallery".$userid;
    @$d = dir($dir);
              
    if ($d) {
      while($entry=$d->read()) {  
        $entry = preg_replace("/ /","%20",$entry);
        $pos = strpos (strtolower($entry), ".jpg");
        if (!($pos === false)) {  
          $arr_pic[] = $dir."/".$entry; } }
      $d->close(); }
    
    $CONST_WIDTH = 250;
    //Find image h and w
    $size = getimagesize($arr_pic[$pic-1]);
    
    $w = $size[0];
    $h = $size[1];
    
    if($w > $CONST_WIDTH){
        //Find %
        $percent = $w / $CONST_WIDTH;
        $w = $w / $percent;
        $h = $h / $percent;
    }
    
    @sort ($arr_pic);    
    $total  = sizeof($arr_pic);
    echo "<div align=\"center\"><img width=\"$w\" height=\"$h\" src=".$arr_pic[$pic-1]."><br>";[/code]

Share this post


Link to post
Share on other sites

a guess


$w = $size[0];
$h = $size[1];

This
[code]
$w = $size[0];
$h = $size[0];
[/code]

or

[code]
$w = $size[1];
$h = $size[1];
[/code]

good luck only learning my self please always back you files up.

Share this post


Link to post
Share on other sites
Nope, still didn't work. Any other ideas out there???

Share this post


Link to post
Share on other sites
Could be that the array sort is screwing up the array indexes.

Share this post


Link to post
Share on other sites
What are the PHP versions on both your local machine and the host?

Share this post


Link to post
Share on other sites
[!--quoteo(post=361711:date=Apr 4 2006, 09:21 PM:name=cmgmyr)--][div class=\'quotetop\']QUOTE(cmgmyr @ Apr 4 2006, 09:21 PM) [snapback]361711[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Local: 4.4.0
Server: 4.3.10

Thanks,
-Chris
[/quote]

looking at your code and at the post by [b]Barand[/b], I think he's hit the nail on the head. Have you tried what he suggested? Lose the @sort line (for the purpose of testing) and see what happens.

Share this post


Link to post
Share on other sites
Ok...that fixed the size problem...but caused another.

The customers are allowed 5 photos. I originally had it set up to where they can re-name the photos to change the order of them on their profile, but now it's not working like that. The way that it is set up now it shows the second picture [$pic-1] when I try [$pic-2] none of the images show up.

Is there a way to get around this one?

Thanks

Share this post


Link to post
Share on other sites
try changing the second part of your code

[code]    $CONST_WIDTH = 250;
    @sort ($arr_pic);

    foreach ($arr_pic as $picfile) {
        //Find image h and w
        $size = getimagesize($picfile);

        $w = $size[0];
        $h = $size[1];

        if($w > $CONST_WIDTH){
            //Find %
            $percent = $w / $CONST_WIDTH;
            $w = $w / $percent;
            $h = $h / $percent;
        }
        echo "<div align=\"center\"><img width=\"$w\" height=\"$h\" src=\"$picfile\"><br>";
    }
[/code]

Share this post


Link to post
Share on other sites
FIXED!

I moved the sort more to the top:[code]@sort ($arr_pic);
$CONST_WIDTH = 250;[/code]

Thanks for all of your help!

Share this post


Link to post
Share on other sites

×

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.