Solved

php, gd library on pair networks (glikk server)

Posted on 2004-10-29
377 Views
Last Modified: 2007-12-19
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&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.

thanks,
brad
0
Question by:bradnoble
    5 Comments
     
    LVL 48

    Expert Comment

    by:hernst42
    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
     

    Author Comment

    by:bradnoble
    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
     
    LVL 10

    Expert Comment

    by:frugle
    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
     
    LVL 48

    Accepted Solution

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

    Author Comment

    by:bradnoble
    hernst42, you rock.  that was it.  thanks!

    0

    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? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=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