= count($words))
            {
                $lines[] = $currentLine;
                break;
            }
            //Check to see if we can add another word to this line
            $metrics = $image->queryFontMetrics($draw, $currentLine . ' ' . $words[$i+1]);
            while($metrics['textWidth'] <= $maxWidth)
            {
                //If so, do it and keep doing it!
                $currentLine .= ' ' . $words[++$i];
                if($i+1 >= count($words))
                    break;
                $metrics = $image->queryFontMetrics($draw, $currentLine . ' ' . $words[$i+1]);
            }
            //We can't add the next word to this line, so loop to the next line
            $lines[] = $currentLine;
            $i++;
            //Finally, update line height
            if($metrics['textHeight'] > $lineHeight)
                $lineHeight = $metrics['textHeight'];
        }
        return array($lines, $lineHeight);
    }
    
    function displayImage($quote, $person, $imageLoc)
    {
        $draw = new ImagickDraw();
        $image = new Imagick();
        $image->readImage($imageLoc);
        //grayscale
        //$image->modulateImage(100, 0, 100);
        /* Green text */
        $draw->setFillColor("rgb(0,255,0)");
        /* Font properties */
        $draw->setFont('Bookman-DemiItalic');
        
        $fontsize = 0.05 * $image->getimagewidth();
        
        $draw->setFontSize( "$fontsize" );
        
        //width = 1180 font is 50
        //width = 300 font is 15
        
        //font = slope of diff(width) + x intercept
        
        $xpos = $image->getimagewidth()/4;
        $ypos = $image->getimageheight()/4;
        
        
        $msg = '"' . $quote . '"' . " - $person";
        list($lines, $lineHeight) = wordWrapAnnotation($image, $draw, $msg, $image->getimagewidth() /2);
        for($i = 0; $i < count($lines); $i++)
        {
            $image->annotateImage($draw, $xpos, $ypos + $i*$lineHeight, 0, $lines[$i]);
        }
        /* Give image a format */
        $image->setImageFormat('png');
        echo '';
    }
    function printHalf($query)
    {
        //random
        
        $r = mysqli_query ($dbc, $query);
        while($row = mysqli_fetch_array($r))
        {
            $q2 = "select name from people where person_id='" . $row['person_id'] . "' limit 1";
            $r2 = mysqli_query($dbc, $q2);
            while($row2 = mysqli_fetch_array($r2))
            {
                $images = glob('../img/*');
                displayImage($row['quote'], $row2['name'], $images[rand(0, count($images) - 1)]);
            }
        }
        echo '';
    }
    
    
    echo '