php, gd library on pair networks (glikk server)

Hi EE,

here's a reference page:
http://www.afpfire.com/maintenance

this page includes a script to resize jpegs on the fly, using php.  This works perfectly on most servers, including locally on my machine and at mediatemple (http://www.bradnoble.com/installation).  for some reason, this script is not working on pair networks -- where it needs to work for my client.  

pair has php 4.3.8 with gd bundled (2.0.23 compatible)

here's my resize script, which works at mediatemple (php 4.3.3 with gd bundled (2.0.15 compatible))

script, resize_image.php:
<?php

$image = $HTTP_GET_VARS['image'];
$max_width = $HTTP_GET_VARS['max_width'];
$max_height = $HTTP_GET_VARS['max_height'];

if (!$max_width)
  $max_width = 800;
if (!$max_height)
  $max_height = 800;

$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];

$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;

if ( ($width <= $max_width) && ($height <= $max_height) ) {
  $tn_width = $width;
  $tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
  $tn_height = ceil($x_ratio * $height);
  $tn_width = $max_width;
}
else {
  $tn_width = ceil($y_ratio * $width);
  $tn_height = $max_height;
}

if (strstr($image,'.jpg') || strstr($image,'.jpeg') || strstr($image,'.jpe'))
{
      $src = @ImageCreateFromJpeg($image);
      //use imagecreatetruecolor instead of imagecreate to optimize color
      //$dst = ImageCreate($tn_width,$tn_height);
      $dst = imagecreatetruecolor($tn_width,$tn_height);
      ImageCopyResized($dst, $src, 0, 0, 0, 0,
            $tn_width,$tn_height,$width,$height);
//      header('Content-type: image/jpeg');
      ImageJpeg($dst, null, -1);
      ImageDestroy($src);
      ImageDestroy($dst);
}
else if (strstr($image,'.png'))
{
      $src = @imagecreatefrompng($image);
      $dst = imagecreate($tn_width,$tn_height);
      imagecopyresized($dst, $src, 0, 0, 0, 0,
            $tn_width,$tn_height,$width,$height);
      header('Content-type: image/png');
      Imagepng($dst);
      ImageDestroy($src);
      ImageDestroy($dst);

}
?>

this script is pointed to by the following img tag, in the php file noted above (note: $host refers to a global php variable; $width and $height are controlled by the user and with the other vars come from a dbase):
$var .=  "<img src=\"/f/resize_image.php?image=http://$host/media/$imagefilename&max_width=$width&max_height=$height\" alt = \"$imagetitle. $imagedescription\" />";

any help is greatly appreciated.  

oh, this may be involved, too: i'm using an /.htaccess file at the root, which includes the following:
# /.htaccess
Options FollowSymLinks
# on a web server other than local development server, you must turn options followsymlinks ON

RewriteEngine ON
# enable the rewrite

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ([-.a-zA-Z_0-9]+)$ $1

RewriteRule ([-.a-zA-Z_0-9]+)/?$ /page.php?pagealias=$1 [NC]

the rewrite here is working perfectly, but perhaps the directory or file conditions above are involved in some way.

thanks,
brad
bradnobleAsked:
Who is Participating?
 
hernst42Connect With a Mentor Commented:
The problem is that allow_url_fopen is set to off, so you can not load remote images via http:// links. But that is what you are doing in your script.

This value can only be changed in php.ini or httpd.conf. As the admin of that server to set it to On. It is not possible to do it in a htacess-file:
http://de3.php.net/ini_set
0
 
hernst42Commented:
If it works with "older" versions it should also be able to run with that newer versions. Maybe there are some settings on the client that prevent correct running like
safe_mode,
allow_url_fopen

Maybe if you compare the php - settings of those two version you might get the point what's the problem is
0
 
bradnobleAuthor Commented:
hernst42,
thanks.  i've tried using /.htaccess to turn safe mode ON, but it didn't change anything as it relates to the resize script.  can I use /.htaccess to do what you're suggesting with allow_url_fopen?  how do i write it in the /.htacess file?

here's the phpinfo() for the new server:
http://www.afpfire.com/phpinfo.php

see anything wrong there?

thanks,
brad
0
 
frugleCommented:
Can you elaborate on "not working" ?

nothing is reportedly broken in 2.0.23 and no fixes have been issued for the functions you are using in the latest version (2.0.28)

is the script failing? what error?

is the file not copying? does the server have write permissions to your image directory?

help us out a bit :-)

Mike
0
 
bradnobleAuthor Commented:
hernst42, you rock.  that was it.  thanks!

0
All Courses

From novice to tech pro — start learning today.