Jump to content


Photo

Image Problems


  • Please log in to reply
10 replies to this topic

#1 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 27 March 2006 - 03:09 AM

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!

    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>";


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 March 2006 - 03:25 AM


a guess


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

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

or

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

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


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 27 March 2006 - 08:57 PM

Nope, still didn't work. Any other ideas out there???

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 28 March 2006 - 12:07 PM

Could be that the array sort is screwing up the array indexes.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 28 March 2006 - 02:14 PM

So what do I have to do to fix it?

#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 28 March 2006 - 02:20 PM

What are the PHP versions on both your local machine and the host?

Info: PHP Manual


#7 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 04 April 2006 - 08:21 PM

Local: 4.4.0
Server: 4.3.10

Thanks,
-Chris

#8 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 04 April 2006 - 09:07 PM

[!--quoteo(post=361711:date=Apr 4 2006, 09:21 PM:name=cmgmyr)--][div class=\'quotetop\']QUOTE(cmgmyr @ Apr 4 2006, 09:21 PM) View Post[/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 Barand, 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.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#9 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 05 April 2006 - 02:30 AM

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

#10 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 05 April 2006 - 08:34 AM

try changing the second part of your 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>";
    }

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#11 cmgmyr

cmgmyr
  • Members
  • PipPipPip
  • Advanced Member
  • 1,278 posts
  • LocationUSA

Posted 05 April 2006 - 01:14 PM

FIXED!

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

Thanks for all of your help!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users