...

View Full Version : imagecreatetruecolor help !



sccottt
07-27-2007, 07:09 PM
i've got this code (in the midst of a bunch of other code):



$file = $_POST['file'];
$trgt_w = $_POST['w'];
$trgt_h = $_POST['h'];

list($w, $h) = getimagesize($file);
echo "w " . $w . ", h " . $h;

$src = imagecreatefromjpeg($file);
echo " imagecreatefromjpeg";

$thm = imagecreatetruecolor($trgt_w, $trgt_h);
echo " imagecreatetruecolor";



I noticed that my code wasn't always executing all the way through. So, I put in those echo lines, and noticed that for SOME images, the "imagecreatetruecolor" echo line never gets executed.

It seems that for larger, say desktop background sized, images, the code quits before getting to that echo line... as it never returns that echo. For smaller images, the code works through that line and perfectly through the rest of the code.

I don't know a ton of PHP, so I am at an impass here. Anything strike anyone as to why this code wouldn't work for larger images? It needs to work for larger images. Am I missing something else?

rafiki
07-27-2007, 07:20 PM
$file = $_POST['file'];
$trgt_w = $_POST['w'];
$trgt_h = $_POST['h'];

list($w, $h) = getimagesize($file);
echo "w : $w , h : $h; // no concatination needed.

$src = imagecreatefromjpeg($file);
echo " imagecreatefromjpeg: $file."; //echo more values

$thm = imagecreatetruecolor($trgt_w, $trgt_h);
echo " imagecreatetruecolor: $trgt_w : $trgt_h."; // echo more values

sccottt
07-27-2007, 07:28 PM
yeah, those echo lines are just for debugging all the variables come through when i modify the code as you describe.

except, still for larger images, the echo " imagecreatetruecolor: $trgt_w : $trgt_h." doesn't come out of the php, as if the code is quitting completely right before that line.

rafiki
07-27-2007, 07:33 PM
sorry i missed a " try
echo "w : $w , h : $h"; // no concatination needed.
do you have an onlin example of the code at work, also turn on full error reporting.

sccottt
07-27-2007, 07:39 PM
i'm actually calling the php through flash, which doesn't let you see any of the errors (hence the echoes for debugging).

let me see if i can get something non-flash hooked up real quick...

sccottt
07-27-2007, 07:41 PM
also, how do i turn on full error reporting with php ?

rafiki
07-27-2007, 07:51 PM
look up error_reporting() on php.net/error-reporting

whizard
07-27-2007, 07:52 PM
http://us2.php.net/manual/en/function.error-reporting.php

HTH
Dan

sccottt
07-27-2007, 07:59 PM
Aaeeight ... here we go... i've got a demo basically showing what happens up at http://sccottt.com/coding_forums/

the php is such:



<?php

error_reporting(E_ALL);

$file = $_POST['file'];
$new_file = $_POST['newFile'];
$trgt_w = $_POST['w'];
$trgt_h = $_POST['h'];
$delete_orig = $_POST['deleteOrig'];

if (strlen($file) > 0 &&
strlen($new_file) > 0 &&
strlen($trgt_w) > 0 &&
strlen($trgt_h) > 0 &&
strlen($delete_orig) > 0) {

list($w, $h) = getimagesize($file);
echo "w: $w, h: $h";

$src = imagecreatefromjpeg($file);
echo " imagecreatefromjpeg( $file )";

$thm = imagecreatetruecolor($trgt_w, $trgt_h);
echo " imagecreatetruecolor ( $trgt_w , $trgt_h )";

$wm = $w / $trgt_w;
$hm = $h / $trgt_h;
$half_trgt_w = $trgt_w / 2;
$half_trgt_h = $trgt_h / 2;

if ($wm > $hm) {
$adj_w = $w / $hm;
$half_w = $adj_w / 2;
$int_w = $half_w - $half_trgt_w;
imagecopyresampled($thm, $src, -$int_w, 0, 0, 0, $adj_w, $trgt_h, $w, $h);

} elseif (($wm < $hm) || ($wm == $hm)) {
$adj_h = $h / $wm;
$half_h = $adj_h / 2;
$int_h = $half_h - $half_trgt_h;
imagecopyresampled($thm, $src, 0, -$int_h, 0, 0, $trgt_w, $adj_h, $w, $h);

} else {
imagecopyresampled($thm, $src, 0, 0, 0, 0, $trgt_w, $trgt_h, $w, $h);

}
imagejpeg($thm, $new_file, 100);

if ($delete_orig == "true") {
unlink($file);
}
}

echo "<br><br>Original:<br><img src=$file><br><br>New (supposed to be resized):<br><img src=$new_file>";

?>


and... well, you can read the HTML


here you can see, when i try a larger image (http://sccottt.com/coding_forums/bigger.jpg), the code seems to quit in the middle of it.

sccottt
07-27-2007, 08:02 PM
ahh... no sh*t, it started working !

rafiki
07-27-2007, 08:03 PM
lol Congratulations :D

sccottt
07-27-2007, 08:03 PM
This must be a problem with my MAMP server running on my computer.

Seems to work online.


Damn, I am so embarrassed.

rafiki
07-27-2007, 08:05 PM
heh, theres always misconfigurations on local servers as to live servers which mess up the script :) dont worry about it it happens to all of us...

sccottt
07-27-2007, 08:08 PM
well, thanks anyhow :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum