Jragon Posted November 15, 2010 Share Posted November 15, 2010 Hey guys, I am making a quotes siggy, code: <?php /** * @author Jragon * @copyright 2010 */ $textfile = "quotes.txt"; $quotes = array(); if (file_exists($textfile)) { $quotes = explode("\n", file_get_contents($textfile)); srand((float)microtime() * 10000000); $string = $quotes[array_rand($quotes)]; $string = wordwrap($string, 100, "\n", true); text_to_image($string, 800); } else { $string = "Sig file non-existant..."; } function text_to_image($text, $image_width, $colour = array(0, 244, 34), $background = array(0, 0, 0)) { $font = 5; $line_height = 15; $padding = 2; $text = wordwrap($text, ($image_width/10)); $lines = explode("\n", $text); $image = imagecreate($image_width, ((count($lines) * $line_height)) + ($padding * 2)); $background = imagecolorallocate($image, $background[48], $background[44], $background[44]); $colour = imagecolorallocate($image, $colour[0], $colour[1], $colour[2]); imagefill($image, 0, 0, $background); $i = $padding; foreach ($lines as $line) { imagestring($image, $font, $padding, $i, trim($line), $colour); $i += $line_height; } header("Content-type: image/jpeg"); imagejpeg($image); imagedestroy($image); exit; } ?> What i want it to do is have the lines the same legnth, and when a quote is smaller the image to shrink. Thanks jragon Link to comment https://forums.phpfreaks.com/topic/218723-image-manipulation-auto-image-resizing/ Share on other sites More sharing options...
Jragon Posted November 15, 2010 Author Share Posted November 15, 2010 Anyone know how? Link to comment https://forums.phpfreaks.com/topic/218723-image-manipulation-auto-image-resizing/#findComment-1134494 Share on other sites More sharing options...
BlueSkyIS Posted November 15, 2010 Share Posted November 15, 2010 maybe try getting the width/height of the lines first and adjust image size accordingly: $width = imagefontwidth($font_size) * strlen($string); $height = imagefontheight($font_size); Link to comment https://forums.phpfreaks.com/topic/218723-image-manipulation-auto-image-resizing/#findComment-1134496 Share on other sites More sharing options...
Jragon Posted November 15, 2010 Author Share Posted November 15, 2010 This is my new code: <?php /** * @author Jragon * @copyright 2010 */ $textfile = "quotes.txt"; $quotes = array(); if (file_exists($textfile)) { $quotes = explode("\n", file_get_contents($textfile)); srand((float)microtime() * 10000000); $string = $quotes[array_rand($quotes)]; $string = wordwrap($string, 100, "\n", true); } else { $string = "Sig file non-existant..."; } function text_to_image($text){ //test $width = imagefontwidth($font_size) * strlen($string); $height = imagefontheight($font_size); echo $width . "<br />" . $hight; //end test $colour = array(0, 244, 34); $background = array(0, 0, 0); $font_size = 5; $line_height = 15; $padding = 2; $text = wordwrap($text, ($image_width/10)); $lines = explode("\n", $text); $image = imagecreate($width, $height); $background = imagecolorallocate($image, $background[48], $background[44], $background[44]); $colour = imagecolorallocate($image, $colour[0], $colour[1], $colour[2]); imagefill($image, 0, 0, $background); $i = $padding; foreach ($lines as $line) { imagestring($image, $font, $padding, $i, trim($line), $colour); $i += $line_height; } header("Content-type: image/jpeg"); imagejpeg($image); imagedestroy($image); exit; } ?> It now outputs just the width and doesnt make a picture Link to comment https://forums.phpfreaks.com/topic/218723-image-manipulation-auto-image-resizing/#findComment-1134517 Share on other sites More sharing options...
Jragon Posted November 15, 2010 Author Share Posted November 15, 2010 Please, i realy need some help Link to comment https://forums.phpfreaks.com/topic/218723-image-manipulation-auto-image-resizing/#findComment-1134628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.