php, gd library on pair networks (glikk server)

Posted on 2004-10-29
Last Modified: 2007-12-19
Hi EE,

here's a reference page:

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 (  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:

$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,
//      header('Content-type: image/jpeg');
      ImageJpeg($dst, null, -1);
else if (strstr($image,'.png'))
      $src = @imagecreatefrompng($image);
      $dst = imagecreate($tn_width,$tn_height);
      imagecopyresized($dst, $src, 0, 0, 0, 0,
      header('Content-type: image/png');


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&amp;max_width=$width&amp;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.

Question by:bradnoble
    LVL 48

    Expert Comment

    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

    Maybe if you compare the php - settings of those two version you might get the point what's the problem is

    Author Comment

    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:

    see anything wrong there?

    LVL 10

    Expert Comment

    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 :-)

    LVL 48

    Accepted Solution

    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:

    Author Comment

    hernst42, you rock.  that was it.  thanks!


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    857 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now