0 ? $maxImageWidth : ( ( $rect[2] - $rect[0] ) + ( ( integer ) ( ( $rect[2] - $rect[0] ) / $textLen ) ) ) ); $imageHeight = abs( $rect[7] ) + ( ( integer ) ( $textSize * 1 ) ); $xOffset = abs( $rect[ 0 ] ); $yOffset = $textSize; } else { $imageWidth = ( $imageWidth > 0 ? $imageWidth : ( $textLen * $charWidth ) ); $imageHeight = ( $imageHeight > 0 ? $imageHeight : ( $textSize + 18 ) ); $xOffset = $xOffset; $yOffset = ( $yOffset > 0 ? $yOffset : ( $imageHeight - $dropShadow - ( ( integer ) ( $textSize / 2 ) ) ) ); } $words = explode( ' ', $text ); $numWords = count( $words ); $lines = array( $words[0] ); $currentLine = 0; for( $i = 1; $i < $numWords; $i++ ) { $lineSize = imagettfbbox( $textSize, 0, $font, ( $lines[$currentLine] . ' ' . $words[$i] ) ); if ( $lineSize[2] - $lineSize[0] < $imageWidth ) { $lines[$currentLine] .= ' ' . $words[$i]; } else { $currentLine++; $lines[$currentLine] = $words[$i]; } } $imageHeight = $imageHeight + ( $imageHeight * $currentLine ); $imageWidth = ( $imageWidth > 800 ? 800 : $imageWidth ); $textSize = $textSize; $angle = $textAngle; // Create the image $im = imagecreatetruecolor( $imageWidth, $imageHeight ); // Create some colors $white = imagecolorallocate( $im, 255, 255, 255 ); $grey = imagecolorallocate( $im, 128, 128, 128 ); $black = imagecolorallocate( $im, 0, 0, 0 ); $bgColor = imagecolorallocate( $im, $bgColorR, $bgColorG, $bgColorB ); $fontColor = imagecolorallocate( $im, $fontColorR, $fontColorG, $fontColorB ); if ( $bgTransparent == 1 ) { imagecolortransparent ( $im, $bgColor ); } imagefilledrectangle( $im, 0, 0, $imageWidth, $imageHeight, $bgColor ); if ( $dropShadow > 0 ) { // Add some shadow to the text imagettftext( $im, $textSize, $angle, ( $xOffset + $dropShadow ), ( $yOffset + $dropShadow ), $grey, $font, $text ); } // Add the text if ( $useNewCalc ) { $lineCount = 0; $additionalLineOffest = ( $yOffset + $dropShadow + ( ( integer ) ( $textSize / 3 ) ) ) + 4; foreach ( $lines as $key => $line ) { $lineYOffest = $textSize + ( $additionalLineOffest * $lineCount ) + 4; imagettftext( $im, $textSize, $angle, ( $xOffset + $dropShadow ), $lineYOffest, $fontColor, $font, $line ); // Increment Y so the next line is below the previous line $lineCount++; } } else { imagettftext( $im, $textSize, $angle, $xOffset, $yOffset, $fontColor, $font, $text ); } // Using imagepng() results in clearer text compared with imagejpeg() header( 'Content-type: image/png' ); imagepng( $im ); imagedestroy( $im ); ?>