Help - Search - Members - Calendar
Full Version: Image Resize Problem
Zymic Webmaster Forums > Zymic Free Web Hosting > Zymic Free Web Hosting - General Discussion & Help
Spider
Hi,

I am happy with the hosting posibilitys from zymic, but at this moment i am having some problems with resizing and auto-thumbnail pics on the gallery system i was using.

I am receiving the next error when trying to resize a picture to smaller format to decrease space.

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 11392 bytes) in /www/zzl.org/s/p/i/spider/htdocs/includes/image_utils.php on line 80

Now i found several topics that having the same problem and redirecting to a problem that we are sharing a server and someone else might be in the way, i tried several times on the day and receiving the error every time.

After doing some other tests with smaller pictures they seems to work, but if i interpertate above properly it says that a file can be about 16MB? while my picture is only 1.5mb i am far from that size if you ask me.

Also i read that it might be a php problem in the script, might someone be able to help me out with a possible sollution to avoid reuploading all pictures with a smaller format? (below 1mb?)

Many thanks.

CODE
<?php
/**************************************************************************
* *
* 4images - A Web Based Image Gallery Management System *
* ---------------------------------------------------------------- *
* *
* File: image_utils.php *
* Copyright: © 2002 Jan Sorgalla *
* Email: jan@4homepages.de *
* Web: http://www.4homepages.de *
* Scriptversion: 1.7.6 *
* *
* Never released without support from: Nicky (http://www.nicky.net) *
* *
**************************************************************************
* *
* Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz- *
* bedingungen (Lizenz.txt) f?r weitere Informationen. *
* --------------------------------------------------------------- *
* This script is NOT freeware! Please read the Copyright Notice *
* (Licence.txt) for further information. *
* *
*************************************************************************/
if (!defined('ROOT_PATH')) {
die("Security violation");
}

function init_convert_options() {
global $config, $lang;

$convert_options = array(
"convert_error" => 0,
"convert_tool" => $config['convert_tool'],
"convert_path" => ereg_replace("\/$", "", $config['convert_tool_path'])
);
switch($config['convert_tool']) {
case "im":
$exec = check_executable("convert");
$convert_options['convert_path'] = preg_replace("/\/?(".check_executable("mogrify")."|$exec)+$/i", '', $convert_options['convert_path']);
$convert_options['convert_path'] = $convert_options['convert_path'] . '/' . $exec;
if (!@is_executable($convert_options['convert_path'])) {
$convert_options['convert_error'] = "<b class=\"marktext\">".$lang['im_error']."</b><br />\n".$lang['check_module_settings'];
}
break;
case "gd":
$convert_options['convert_gd2'] = false;

if (defined('CONVERT_IS_GD2')) {
$convert_options['convert_gd2'] = CONVERT_IS_GD2 == 0 ? false : true;
} elseif (function_exists("imagecreatetruecolor") && function_exists("imagecopyresampled")) {
$convert_options['convert_gd2'] = true;
}

if (!function_exists("imagetypes")) {
$convert_options['convert_error'] = (defined("IN_CP")) ? "<b class=\"marktext\">".$lang['gd_error']."</b><br />\n".$lang['check_module_settings'] : 1;
}
break;
case "netpbm":
if (!@is_executable($convert_options['convert_path']."/".check_executable("pnmscale"))) {
$convert_options['convert_error'] = (defined("IN_CP")) ? "<b class=\"marktext\">".$lang['netpbm_error']."</b><br />\n".$lang['check_module_settings'] : 1;
}
break;
default:
$convert_options['convert_error'] = (defined("IN_CP")) ? "<b class=\"marktext\">".$lang['no_convert_module']."</b><br />\n".$lang['check_module_settings'] : 1;
}
return $convert_options;
}

function resize_image_gd($src, $dest, $quality, $width, $height, $image_info) {
global $convert_options;

$types = array(1 => "gif", 2 => "jpeg", 3 => "png");
if ($convert_options['convert_gd2']) {
$thumb = imagecreatetruecolor($width, $height);
}
else {
$thumb = imagecreate($width, $height);
}
$image_create_handle = "imagecreatefrom".$types[$image_info[2]];
if ($image = $image_create_handle($src)) {
if ($convert_options['convert_gd2']) {
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
}
else {
imagecopyresized($thumb, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
}

if ($image_info[2] == 3) {
$quality = 9;
}

$image_handle = "image".$types[$image_info[2]];
$image_handle($thumb, $dest, $quality);
imagedestroy($image);
imagedestroy($thumb);
}
return (file_exists($dest)) ? 1 : 0;
}

function resize_image_im($src, $dest, $quality, $width, $height, $image_info) {
global $convert_options;

$command = $convert_options['convert_path']." -quality ".$quality." -antialias -sample $width"."x"."$height \"$src\" \"$dest\"";
system($command);
return (file_exists($dest)) ? 1 : 0;
}

function resize_image_netpbm($src, $dest, $quality, $width, $height, $image_info) {
global $convert_options;

$convert_path = $convert_options['convert_path'];
$types = array(1 => "gif", 2 => "jpeg", 3 => "png");
$target = ($width > $height) ? $width : $height;
$command = $convert_path."/".check_executable($types[$image_info[2]]."topnm")." ".$src." | ".$convert_path."/".check_executable("pnmscale")." --quiet -xysize ".$target." ".$target." | ";
if ($image_info[2] == 1) {
$command .= $convert_path."/".check_executable("ppmquant")." 256 | " . $convert_path."/".check_executable("ppmtogif")." > ".$dest;
}
elseif ($image_info[2] == 3) {
$command .= $convert_path."/".check_executable("pnmtopng")." > ".$dest;
}
else {
$jpeg_exec = (file_exists($convert_path."/".check_executable("pnmtojpeg"))) ? check_executable("pnmtojpeg") : check_executable("ppmtojpeg");
$command .= $convert_path."/".$jpeg_exec." --quality=".$quality." > ".$dest;
}
system($command);
return (file_exists($dest)) ? 1 : 0;
}

function get_width_height($dimension, $width, $height, $resize_type = 1) {
if ($resize_type == 2) {
$new_width = $dimension;
$new_height = floor(($dimension/$width) * $height);
}
elseif ($resize_type == 3) {
$new_width = floor(($dimension/$height) * $width);
$new_height = $dimension;
}
else {
$ratio = $width / $height;
if ($ratio > 1) {
$new_width = $dimension;
$new_height = floor(($dimension/$width) * $height);
}
else {
$new_width = floor(($dimension/$height) * $width);
$new_height = $dimension;
}
}
return array("width" => $new_width, "height" => $new_height);
}

function create_thumbnail($src, $dest, $quality, $dimension, $resize_type) {
global $convert_options;

if (file_exists($dest)) {
@unlink($dest);
}
$image_info = (defined("IN_CP")) ? getimagesize($src) : @getimagesize($src);
if (!$image_info) {
return false;
}
$width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);
$resize_handle = "resize_image_".$convert_options['convert_tool'];
if ($resize_handle($src, $dest, $quality, $width_height['width'], $width_height['height'], $image_info)) {
@chmod($dest, CHMOD_FILES);
return true;
}
else {
return false;
}
}

function resize_image($file, $quality, $dimension, $resize_type = 1) {
global $convert_options;
$image_info = (defined("IN_CP")) ? getimagesize($file) : @getimagesize($file);
if (!$image_info) {
return false;
}
$file_bak = $file.".bak";
if (!rename($file, $file_bak)) {
return false;
}
$width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);
$resize_handle = "resize_image_".$convert_options['convert_tool'];
if ($resize_handle($file_bak, $file, $quality, $width_height['width'], $width_height['height'], $image_info)) {
@chmod($file, CHMOD_FILES);
@unlink($file_bak);
return true;
}
else {
rename($file_bak, $file);
return false;
}
}
?>



Regards,
Dennis
Trippin7464
http://www.zymic.com/forum/index.php?showtopic=4365
You might find this topic helpful.
Also I'm gonna go ahead and try to run that script on my self hosted server and see if any problems come up.

/* Edit */
First off just so you know, the page you provided is just ONE of MANY MANY pages used to create this upload script.
Trippin7464
Allright well I just ran the script on my own self host, and everything ran fine. So I don't know what to tell you. I think it "COULD" be a GD related issue, where it's eating up alot of memory trying to resize the image.

Does it create the thumbnail correctly?
Spider
QUOTE(Trippin7464 @ Apr 21 2008, 02:20 AM) *
Allright well I just ran the script on my own self host, and everything ran fine. So I don't know what to tell you. I think it "COULD" be a GD related issue, where it's eating up alot of memory trying to resize the image.

Does it create the thumbnail correctly?


thumnails only working when the image is smaller then 1MB resizing works aswell when images are smaller then 1MB.

For the site i was mentioning it's about http://spider.zzl.org.

Trippin7464
Well I don't know. There must be some kind of restriction in PHP or GD stopping you from making new files over 1mb. (Be cause to create a thumbnail and to resize the image it creates a copy of the image in a temp folder first)

I really don't know though, since it worked fine on an unrestricted hosting.
Spider
Any other posiiblitys to make this working, or might there be a solution to use 1 of the other methods to resize and thumnail a picture?

4images is mentioning imagemagick and netpbm aswell as conversion tool, but I am not sure if that is usable on this host?

Regards,
Dennis

edit:
Just tried the same with another gallery system. Installed coppermine succesfull, but also with this system i am receiving above mentioned errors.

After uploading a image (that looks to go properly) thesystem is mentioning the next error:

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 2848 bytes) in /www/zzl.org/s/p/i/spider-develop/htdocs/coppermine/include/picmgmt.inc.php on line 235

tried with both conversion options (gd1 and gd2) both ended with the same error, since i can't try it out with image magick since this is not available.

Any other sollutions that might resolve this problem (perhaps using a httdoc?)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.