Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ImageCreateFromJPEG loop problem

    I have a problem with ImageCreateFromJPEG when running it in a loop.

    The following code will work:

    Code:
    	$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:

    Code:
    	$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:

    Code:
    	$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.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,512
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    What do you mean by "not work"?
    Do you get an error? Does anything happen (like it sort of works?)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •