Jump to content

Is there a function to resize images ?


tmyonline

Recommended Posts

Hi guys:

 

I need to resize images for my current work.  I used the function "getimagesize()" which works fine on my local machine but somehow fails to work on the server after I uploaded.  As a result, the images do not appear online although they do appear locally on my machine.  How should I resolve this?  Otherwise, is there a function to get the width and the height of an image?  Thanks a lot.

 

T

Link to comment
https://forums.phpfreaks.com/topic/77461-is-there-a-function-to-resize-images/
Share on other sites

Hi, thanks for helping me!

 

I'm not sure what version of PHP is running on the server.  I can ask but the lady here just walked out.  On my machine, it's PHP 5 that is running but not sure what's on the server.  Here are the messages I got:

 

Warning: getimagesize() [function.getimagesize]: URL file-access is disabled in the server configuration in /home/.euclid/aamnva/actualaamnva.org/schools/test/lereport.php on line 106

 

Warning: getimagesize(http://memory.loc.gov/pnp/fsa/8c03000/8c03800/8c03875r.jpg) [function.getimagesize]: failed to open stream: no suitable wrapper could be found in /home/.euclid/aamnva/actualaamnva.org/schools/test/lereport.php on line 106

 

Thanks. T

Here's my code for this:

 

list($width, $height) = getimagesize($imageSelect);

  if ($width != 500) {

    $width  = 500;

$height = 500 * ($height/$width);

  }

 

  if ($height > 500) {

    $height = 500;

$width  = 500 * ($width/$height);

  }

 

I also tried:  list($width, $height, $attribute, $type) = getimagesize($imageSelect);

Here's how I referenced the images:

 

$imgSQL    = "SELECT * FROM LOC_item WHERE LOC_key = $LOCKEY AND image like 'http%'";

$imgResult = mysql_db_query($db,$imgSQL,$cid);

$imgRow    = @mysql_fetch_assoc($imgResult);

 

$imageSelect = $imgRow['image'];

  list($width, $height) = getimagesize($imageSelect);

  if ($width != 500) {

    $width  = 500;

$height = 500 * ($height/$width);

  }

 

  if ($height > 500) {

    $height = 500;

$width  = 500 * ($width/$height);

  }

There's your problem... you are referencing your images via a URL path based on your query. This means that, most likely, you do not have the allow_url_fopen flag set to "on." Otherwise, you have to be able to reference your images via their server path instead.

The images are working and displaying fine on my local machine; they just do not appear online.  In other words, the "getimagesize()" function works fine on my computer but not on the server.  So,

 

How do I set the "allow_url_fopen" flag to "on" ?

 

and, how do I reference images via server path ?

 

Any other alternatives to resize images or get their width and height?

 

Thanks, T.

If you'll read the manual page on that setting I linked to, you'll see a note that, due to security reasons, that flag can only be set within the php.ini file on the server. Most likely, your local copy (especially if you're using WAMP, XAMPP or one of the cousins) will have that flag set to "on." You'll need to get your system administrator to change the setting in the php.ini for you. If you would rather reference via server path, it would be the absolute path to the image directory in which you are storing the images (ie, /usr/local/apache/htdocs/images/ or whatever your setup is). The only other way I can think of to get the image size (and this is a hack) would be to display the image and use javascript to measure it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.