unkonwn issue with script: fixed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

unkonwn issue with script: fixed

Post by m3rajk »

for some reason a script is NOT returning on one section.

http://www.findyourdesire.com/new.php?gen=all

shows the issue i'm having. the following script returns the unavailabl pic for ALL the other cases EXCEPT the ltn case. the ltn case is the only one called in the link. here's the script. if you see the issue, could youlet me know? i can't see any difference from the working ones aside from the size.

Code: Select all

<?php
include("/home/dcfydllc/includes/fyd.altincs.php");
// get the function type and picture 
$fn=$_GET['fn'];
$pic=$faup . $_GET['pic'];

if(isset($fn)){ // act on the function
  if($fn==='main'){ // this is the main pic's thumb
    if(is_file($pic)){ // the user uploaded a pic
      $src=ImageCreateFromJPEG($pic);
      $width=ImageSx($src); $height=ImageSy($src);
      $x=250; $y=250; $dst=ImageCreate($x,$y);
      ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
      header('Content-Type: image/png'); ImagePNG($dst);
    }else{ // we need to fill it with something
      $src=ImageCreateFromPNG('sitepics/uona.png');
      $width=ImageSx($src); $height=ImageSy($src);
      $x=250; $y=250; $dst=ImageCreate($x,$y);
      ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
      header('Content-Type: image/png'); ImagePNG($dst);
    }
  }elseif($fn==='thumb'){ // this is the profile page thumbs
    if(is_file($pic)){ // the user uploaded a pic
      $src=ImageCreateFromJPEG($pic);
      $width=ImageSx($src); $height=ImageSy($src);
      $x=125; $y=125; $dst=ImageCreate($x,$y);
      ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
      header('Content-Type: image/png'); ImagePNG($dst);
    }else{
      $src=ImageCreateFromPNG('sitepics/uona.png');
      $width=ImageSx($src); $height=ImageSy($src);
      $x=125; $y=125; $dst=ImageCreate($x,$y);
      ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
      header('Content-Type: image/png'); ImagePNG($dst);
    }
  }elseif($fn==='ltn'){ // this is the lust list/top users/newest users/forums thumb
    if(is_file($pic)){ // the user uploaded a pic
      $src=ImageCreateFromJPEG($pic);
      $width=ImageSx($src); $height=ImageSy($src);
      $x=75; $y=75; $dst=ImageCreate($x,$y);
      ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
      header('Content-Type: image/png'); ImagePNG($dst);
    }else{
      $src=ImageCreateFromPNG('sitepics/unoa.png');
      $width=ImageSx($src); $height=ImageSy($src);
      $x=75; $y=75; $dst=ImageCreate($x,$y);
      ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
      header('Content-Type: image/png'); ImagePNG($dst);
    }
  }elseif($fn==='full'){ # we're making the tagged full size pic (should only be called if it exists & is approved)
    $tag='sitepics/imgtag.png'; # the tag
    $tagimg=ImageCreateFromPNG($tag);
    $tw=ImageSx($tagimg); $th=ImageSy($tagimg);
    $mem=ImageCreateFromJPEG($pic);
    imageCopy($mem, $tagimg, 0, 0, 0, 0, $tw, $th);
    header('Content-Type: image/png'); ImagePNG($mem);
    imageDestroy($mem); imageDestroy($tagimg);
  }else { // there was an error (or we're calling the spacer)
    $src=ImageCreateFromPNG('sitepics/unoa.png');
    $width=ImageSx($src); $height=ImageSy($src);
    $x=75; $y=75; $dst=ImageCreate($x,$y);
    ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
    header('Content-Type: image/png'); ImagePNG($dst);
  }
}else{ // no function, something is wrong
  $src=ImageCreateFromPNG('sitepics/unoa.png');
  $width=ImageSx($src); $height=ImageSy($src);
  $x=75; $y=75; $dst=ImageCreate($x,$y);
  ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
  header('Content-Type: image/png'); ImagePNG($dst);
}
?>
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

i decided to try to make the script more efficient and in doing so switched to witches since they are faster....the new script is one-third the size of the old script AND works right in that case as well as the others (already tested)

Code: Select all

<?php
include("/home/dcfydllc/includes/fyd.altincs.php");
// get the function type and picture 
$pic=$faup.$_GET['pic']; # set the picture

if($_GET['fn']==='full'){ # we're making the tagged full size pic (should only be called if it exists & is approved)
  if(is_file($pic)){ # there is a passed picture
    $tag='sitepics/imgtag.png'; # the tag
    $tagimg=ImageCreateFromPNG($tag);
    $tw=ImageSx($tagimg); $th=ImageSy($tagimg);
    $mem=ImageCreateFromJPEG($pic);
    imageCopy($mem, $tagimg, 0, 0, 0, 0, $tw, $th);
    header('Content-Type: image/png'); ImagePNG($mem);
    imageDestroy($mem); imageDestroy($tagimg);
  }else { // there was an error (or we're calling the spacer)
    $src=ImageCreateFromPNG('sitepics/unoa.png');
    $width=ImageSx($src); $height=ImageSy($src);
    $x=250; $y=250; $dst=ImageCreate($x,$y);
    ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
    header('Content-Type: image/png'); ImagePNG($dst);
  }
}else{ # we're doing one of the others 
  switch ($_GET['fn']){
  case('main'): # main image.
    $x=250; $y=250; # set x & y to 250
    break;
  case('thumb'): # thumbnail.
    $x=125; $y=125; # set x & y to 125
    break;
  default: # thumb for non-profile or error
    $x=75; $y=75; # set x & y to 75
    break;
  }
  if(is_file($pic)){ # there is a passed picture
    $src=ImageCreateFromJPEG($pic); # use the passed picture
  }else{ # there wasn't a picture
    $src=ImageCreateFromPNG('sitepics/uona.png'); # use the default
  }
  $width=ImageSx($src); $height=ImageSy($src); $dst=ImageCreate($x,$y);
  ImageCopyResized($dst,$src,0,0,0,0,$x,$y,$width,$height);
  header('Content-Type: image/png'); ImagePNG($dst);
}
?>
Post Reply