Jump to content

Recommended Posts

Hi,

I have written a page to parse the uploading of images. I usually test it with the default images you get with windows XP (you the sunset one etc..) and everything worked fine... It uploads the image resizes the original outouts it and then creates a thumbnail and again outputs it.

Until...

I tried uploading a larger jpeg (3.1Mb) it uploads it to the php tmp directory and it gets as far as
[code]
imagejpeg($image_p,$target,$jpegqual);
[/code]

and gives up.

here's a snippet from the page, like i said everything works fine until the imagejpeg part.

[code]
if($filetype == "image/pjpeg" or $filetype == "image/jpeg"){
list($orig_width, $orig_height) = getimagesize($tmp_name);
$ext = ".jpg";
$target = $uploaddir.$new_name.$ext;
$target_small = $uploaddir."thumbs/".$new_name.$ext;
$width = $orig_width;
$height = $orig_height;
$width_small = $orig_width;
$height_small = $orig_height;
// RESIZE LARGE IMAGE
if($height > $max_height){
  $width = ($max_height / $height) * $width;
  $height = $max_height;
}
if($width > $max_width){
  $height = ($max_width / $width) * $height;
  $width = $max_width;
}
$image_p = imagecreatetruecolor($width, $height)or die("Cannot Initialize new GD image stream");
$image = imagecreatefromjpeg($tmp_name)or die("Cannot Initialize new GD image stream2");
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height);
imagejpeg($image_p,$target,$jpegqual);
[/code]

i've checked the syntax and i don't think its that

does anyone have any ideas??

Thanks in advance

Seamless.
Link to comment
https://forums.phpfreaks.com/topic/33653-problem-with-imagejpeg/
Share on other sites

i'm not getting one, the server i'm using has errors turned off by default. Is there a statement i can use which will display an error like mysql_error(); does?

I don't really want to have to go in and edit my php.ini, but if i have to i suppose i can.

Seamless
ok, i edited my php.ini to show errors and this is the error i get even though i have increased the memory_limit in the php.ini to 128MB

[quote]
Allowed memory size of 134217728 bytes exhausted (tried to allocate 15488 bytes)
[/quote]

I'm getting a bit nervous now, i've never altered the memory_limit so i have a few questions:

1. Is there a maximum i can increase it to?
2. What are the effects of increasing it?

Seamless
Seamless,

The GD library uses a lot of memory on an image that size.  The best bet is to leave the settings in php.ini as they were and change the value at runtime using [url=http://uk.php.net/manual/en/function.ini-set.php]ini_set()[/url].

So on each page you have GD functions, set this at the top:

[code]<?php
// Increase available memory
ini_set("memory_limit","256M");
?>[/code]

I included a link in a previous post: http://www.phpfreaks.com/forums/index.php/topic,121661.0.html

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.