[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


php, gd library on pair networks (glikk server)

Posted on 2004-10-29
Medium Priority
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 (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:

$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&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.

Question by:bradnoble
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 48

Expert Comment

ID: 12443832
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

ID: 12443901
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

ID: 12444047
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

hernst42 earned 2000 total points
ID: 12444080
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

ID: 12444828
hernst42, you rock.  that was it.  thanks!


Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

656 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