invalid resource error and a related issue

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

invalid resource error and a related issue

Post by m3rajk »

Code: Select all

#find height and width of pics, then verify, adjust to logo if necessary
  $mw=ImageSx('userpics/'.$un.'.jpg');
  $mh=ImageSy('userpics/'.$un.'.jpg'); 

  $t1w=ImageSx('userpics/t1.'.$un.'.jpg'); 
  $t1h=ImageSy('userpics/t1.'.$un.'.jpg');

  $t2w=ImageSx('userpics/t2.'.$un.'.jpg'); 
  $t2h=ImageSy('userpics/t2.'.$un.'.jpg');

  $t3w=ImageSx('userpics/t3.'.$un.'.jpg');
  $t3h=ImageSy('userpics/t3.'.$un.'.jpg'); 

  $t4w=ImageSx('userpics/t4.'.$un.'.jpg'); 
  $t4h=ImageSy('userpics/t4.'.$un.'.jpg'); 

  $sw=ImageSx('userpics/salute.'.$un.'.jpg'); 
  $sh=ImageSy('userpics/salute.'.$un.'.jpg'); 

  if(!($mw)){
    $mw=ImageSx('sitepics/logo.png');
    $mh=ImageSy('sitepics/logo.png'); 
  } # pic didn't exist

  if(!($t1w)){
    $t1w=ImageSx('sitepics/logo.png');
    $t1h=ImageSy('sitepics/logo.png');
  } # pic didn't exist

  if(!($t2w)){
   $t2w=ImageSx('sitepics/logo.png');
   $t2h=ImageSy('sitepics/logo.png');
   } # pic didn't exist

  if(!($t3w)){
    $t3w=ImageSx('sitepics/logo.png');
    $t3h=ImageSy('sitepics/logo.png');
  } # pic didn't exist

  if(!($t4w)){
    $t4w=ImageSx('sitepics/logo.png');
    $t4h=ImageSy('sitepics/logo.png');
  } # pic didn't exist

  if(!($sw)){
    $sw=ImageSx('sitepics/logo.png');
    $sh=ImageSy('sitepics/logo.png');
  } # pic didn't exist
i've tried changing how i call the pictures.. the only one that worked was changing it to

Code: Select all

#find height and width of pics, then verify, adjust to logo if necessary
  $main='userpics/'.$un.'.jpg'; $t1='userpics/t1.'.$un.'.jpg';
  $t2='userpics/t2.'.$un.'.jpg'; $t3='userpics/t3.'.$un.'.jpg';
  $t4='userpics/t4.'.$un.'.jpg'; $salute='userpics/salute.'.$un.'.jpg';
  $logo='sitepics/logo.png';

  $mw=ImageSx($main); $mh=ImageSy($main);
  $t1w=ImageSx($t1); $t1h=ImageSy($t1);
  $t2w=ImageSx($t2); $t2h=ImageSy($t2);
  $t3w=ImageSx($t3); $t3h=ImageSy($t3);
  $t4w=ImageSx($t4); $t4h=ImageSy($t4);
  $sw=ImageSx($salute); $sh=ImageSy($salute);

  if(!($mw)){
    $mw=ImageSx($logo);
    $mh=ImageSy($logo);
  } # pic didn't exist

  if(!($t1w)){
    $t1w=ImageSx($logo); 
    $t1h=ImageSy($logo); 
  } # pic didn't exist

  if(!($t2w)){ 
    $t2w=ImageSx($logo); 
    $t2h=ImageSy($logo); 
  } # pic didn't exist

  if(!($t3w)){ 
    $t3w=ImageSx($logo); 
    $t3h=ImageSy($logo); 
  } # pic didn't exist

  if(!($t4w)){ 
    $t4w=ImageSx($logo); 
    $t4h=ImageSy($logo); 
  } # pic didn't exist

  if(!($sw)){ 
    $sw=ImageSx($logo); 
    $sh=ImageSy($logo); 
  } # pic didn't exist
however, at this point the height and width do not get set. . i know this because the height and witdh are used in a line of html that uses javascript to create a window for the picture and the windows are not being made to the height and width.

i have tried that two ways.

Code: Select all

echo "<a name="#example" href="#example" onClick="window.open('$main', 'pic', 'height=$mh,width=$mw');">";
echo '<a name="#t1" href="#t1" onClick="window.open('''.$t1.'", ''pic'', ''height='.$t1h.',width='.$t1w.''');">';
in both cases the height and width don't work.
Last edited by m3rajk on Fri Jun 20, 2003 4:23 pm, edited 2 times in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Let the code breathe! It's suffocating in there...
maybe that's why it won't work...

[edit: ta for the reformat - makes it a lot easier to read]

Mac
Last edited by twigletmac on Fri Jun 20, 2003 4:30 pm, edited 1 time in total.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

i know it's probably better to change the check to see if the file exists instead of the variable being something other than null, which would mean changing

Code: Select all

if(!($pw)){ 
    $pw=ImageSx($logo); 
    $ph=ImageSy($logo); 
  } # pic didn't exist
to

Code: Select all

if(!(is_file($pic))){ 
    $pw=ImageSx($logo); 
    $ph=ImageSy($logo); 
  } # pic didn't exist
but i still don't see why the height and width aren't being passed
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

If you're just needing the width and height of the image then use getimagesize().

i.e.:

Code: Select all

list($mw, $mh) = getimagesize('userpics/'.$un.'.jpg');
User avatar
releasedj
Forum Contributor
Posts: 105
Joined: Tue Jun 17, 2003 6:35 am

Post by releasedj »

The imageSx() function is part of PHP's image manipulation functions, usually used to create/manipulate images using PHP.. far to complex for what you need.
Post Reply