PDA

View Full Version : ImageCreateFromJPEG loop problem



andll
11-21-2010, 04:06 AM
I have a problem with ImageCreateFromJPEG when running it in a loop.

The following code will work:



$dst = ImageCreateTrueColor(900, 1719);
$src = ImageCreateFromJPEG($a[0][2]);
ImageCopyResampled($dst, $src, $a[0][0], $a[0][1], 0, 0, $widthtarget, $heighttarget, $originalx, $originaly);
$src = ImageCreateFromJPEG($a[1][2]);
ImageCopyResampled($dst, $src, $a[1][0], $a[1][1], 0, 0, $widthtarget, $heighttarget, $originalx, $originaly);
$src = ImageCreateFromJPEG($a[2][2]);
ImageCopyResampled($dst, $src, $a[2][0], $a[2][1], 0, 0, $widthtarget, $heighttarget, $originalx, $originaly);
$src = ImageCreateFromJPEG($a[3][2]);
ImageCopyResampled($dst, $src, $a[3][0], $a[3][1], 0, 0, $widthtarget, $heighttarget, $originalx, $originaly);
$src = ImageCreateFromJPEG($a[4][2]);
ImageCopyResampled($dst, $src, $a[4][0], $a[4][1], 0, 0, $widthtarget, $heighttarget, $originalx, $originaly);
$src = ImageCreateFromJPEG($a[5][2]);
ImageCopyResampled($dst, $src, $a[5][0], $a[5][1], 0, 0, $widthtarget, $heighttarget, $originalx, $originaly);
imagejpeg($dst, "cool.jpg");
imagedestroy($dst);


However this will NOT work:



$dst = ImageCreateTrueColor(900,1719);
for($i=0;$i < count($a);$i++) {
$src = ImageCreateFromJPEG($a[$i][2]);
ImageCopyResampled($dst, $src, $a[$i][0], $a[$i][1], 0, 0, $widthtarget, $heighttarget, $orignalx, $originaly);
}
imagejpeg($dst, "rad.jpg");
imagedestroy($dst);


AND this will NOT work:



$dst = ImageCreateTrueColor(900, 1719);
foreach($a as $row) {
print "<br>\n file from row: " . $row[2] . "<br>\n";
print "<br>\n x: " . $row[0] . "<br>\n";
print "<br>\n y: " . $row[1] . "<br>\n";
$src=ImageCreateFromJPEG($row[2]); // format of array 0: x 1: y 2: file
ImageCopyResampled($dst, $src, $row[0], $row[1], 0, 0, $widthtarget, $heighttarget, $orignalx, $originaly);
}
imagejpeg($dst, "rad.jpg");
imagedestroy($dst);


Why won't the code work when it is run in a loop? I can provide clarification of the code if necessary.

mlseim
11-22-2010, 01:41 AM
What do you mean by "not work"?
Do you get an error? Does anything happen (like it sort of works?)