bausman480 Posted June 5, 2012 Share Posted June 5, 2012 Hi, I'm having trouble wrapping my head around how to write a function.. I need to place a thumbnail photo on a background image x times. (x is stored in the db, width and height of thumbnail are also in db). The trick is the thumbnail has to be tiled next to each other (or underneath each other) depending on the dimensions stored in the db, AND the thumbnail has to be turned 90 degrees of not based on a variable in the db. So i'm trying to create a function that will figure out what the coordinates are that each image needs to be placed at, but its not working. All the variables are passing properly, its just the logic of how to TURN the image and get the coordinates to line up I'm not getting. Here is my code so far, i'd appreciate any help! Thank you! <?php //get vars $_SESSION['width'] = mysql_result($result,0,"width"); $_SESSION['height'] = mysql_result($result,0,"height"); $_SESSION['tiles'] = mysql_result($result,0,"tiles"); $_SESSION['orient'] = mysql_result($result,0,"orient"); //echo $_SESSION['width'], $_SESSION['height'], $_SESSION['tiles'], $_SESSION['orient']; //Source image paths $srcImagePaths = array(); $i=1; for ( ; $i <= $_SESSION['tiles']; ) { $srcImagePaths[] = $_SESSION['cropped']; $i++; } // make base image filled with bg colour $tileWidth = $_SESSION['width']; $tileHeight = $_SESSION['height']; $numberOfTiles = $_SESSION['tiles']; $numTilesFit = $_SESSION['tiles']; $mapImage = imagecreatetruecolor(1800, 1200); $bgColor = imagecolorallocate($mapImage, 50, 40, 0); imagefill($mapImage, 0, 0, $bgColor); //put scr images on base image function indexToCoords1($index) { global $tileWidth, $numberOfTiles, $numTilesFit; $x = ($index % $numTilesFit) * $tileWidth; $y = floor($index / $numTilesFit) * $tileHeight; return Array($x, $y); } function indexToCoords2($index) { global $tileWidth, $numberOfTiles, $numTilesFit; $x = ($index % $numTilesFit) * $tileHeight; $y = floor($index / $numTilesFit) * $tileWidth; return Array($x, $y); } foreach ($srcImagePaths as $index => $srcImagePath) { if($_SESSION['orient'] == 1){ list ($x, $y) = indexToCoords1($index); } elseif($_SESSION['orient'] == 2){ list ($x, $y) = indexToCoords2($index); } $tileImg = imagecreatefromjpeg($srcImagePath); if($_SESSION['orient'] == 1){ $tileImg2 = imagerotate($tileImg,90,0); } elseif($_SESSION['orient'] == 2) { $tileImg2 = imagerotate($tileImg,0,0); } else { echo "Dude, no orientation set"; } imagecopy($mapImage, $tileImg2, $x, $y, 0, 0, $tileWidth, $tileHeight); imagedestroy($tileImg2); imagedestroy($tileImg); }?> Quote Link to comment https://forums.phpfreaks.com/topic/263729-help-writing-image-tiling-function/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.