0

hi all I have the code below, and I am getting this error:
The image "http://127.0.0.1/newsite/thumbnailgenerator.php" cannot be displayed because it contains errors. think this should be correct, what could the problem be? please help if you can. thanks :)

<?php 
header('Content-type: image/jpg');
function create_thumb_nail($array_image)
{


if (isset($array_image['image'])){
$image = "images/".$array_image['image'];

$image_size = getimagesize($image);
$image_width = $image_size(0);
$image_height =$image_size(1);

$new_size = ($image_width + $image_height)/($image_width*($image_height/45));
$new_width - $image_width = $new_size;
$new_height = $image_height = $new_size;

$new_image = imagecreattruecolor($new_width, $new_height);
$old_image = imagecreatefromjepg($image);

imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
iamgejpeg($new_image, $image.'.thumb.jpg');
}

}

$row = array("image"=>"space.jpg");
 create_thumb_nail($row);
?>
4
Contributors
8
Replies
10
Views
6 Years
Discussion Span
Last Post by 007tron
0

How is your database set up.. Are you storing the picture in a BLOB or locally?

I am storing it locally, in the images folder. I noticed a few code errors and I have fixed them but its still not working.

new code looks like this:

<?php 
header('Content-type: image/jpg');
function create_thumb_nail($array_image)
{


if (isset($array_image['image'])){
$image = "images/".$array_image['image'];

$image_size = getimagesize($image);
$image_width = $image_size(0);
$image_height =$image_size(1);

$new_size = ($image_width + $image_height)/($image_width*($image_height/45));
$new_width =$image_width * $new_size;
$new_height = $image_height * $new_size;

$new_image = imagecreattruecolor($new_width, $new_height);
$old_image = imagecreatefromjepg($image);

imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image, $image.'.thumb.jpg');
}

}

$row = array("image"=>"space.jpg");
 create_thumb_nail($row);
?>

Edited by 007tron: n/a

0

My suggestion is //comment header(); for a moment and try to write your img output to a local file and see what errors PHP will throw.

0
$image_width = $image_size(0);
$image_height =$image_size(1);

shouldn't that be:

$image_width = $image_size[0];
$image_height =$image_size[1];
0

My suggestion is //comment header(); for a moment and try to write your img output to a local file and see what errors PHP will throw.

that was really helpful, found a few errors and fixed them problems with image functions (misspelling).Now I am getting this error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 45888 bytes) in C:\xampp\htdocs\newsite\thumbnail_generator.php on line 19

any ideas?

0
$image_width = $image_size(0);
$image_height =$image_size(1);

shouldn't that be:

$image_width = $image_size[0];
$image_height =$image_size[1];

Yes that helped as well, now trying solve this:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 45888 bytes) in C:\xampp\htdocs\newsite\thumbnail_generator.php on line 19

0
$new_image = [B]imagecreattruecolor[/B]($new_width, $new_height);
$old_image = [B]imagecreatefromjepg[/B]($image);

Are you sure that you've spelled these correctly?

0
$new_image = [B]imagecreattruecolor[/B]($new_width, $new_height);
$old_image = [B]imagecreatefromjepg[/B]($image);

Are you sure that you've spelled these correctly?

I have those mistakes already sorted out but image won't display and when I comment out the header part.I increased the memory_limit in the php.ini to 1024M, but still getting errors ie. Php doesn't display anything

Here is the modified code

$row = array("image"=>"space.jpg");
$array_image=$row;
if (isset($array_image['image'])){
$image = "images/".$array_image['image'];

$image_size = getimagesize($image);
$image_width = $image_size[0];
$image_height =$image_size[1];

$new_size = ($image_width + $image_height)/($image_width*($image_height/45));
$new_width =$image_width * $new_size;
$new_height = $image_height * $new_size;

$new_image = imagecreatetruecolor ($new_width, $new_height);
$old_image = imagecreatefromjpeg ($image);

imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image, $image.'.thumb.jpg');

}

Edited by 007tron: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.