Jump to content

graves_it

Members
  • Posts

    16
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

graves_it's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Here is what I have so far, still not working but it is an attempt to do what was said in the previous suggestions. Any ideas? $text="Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem http://somelongurl.com/then-we-make-it-super-long-with-some-more/ Lorem Ipsum Lorem Ipsum Lorem Ipsum http://www.anotherlinks.com/"; $string_chunks = explode(' ', $text); // Takes the split and recombine foreach ($string_chunks as $chunk) { $start_bit = false; // before anything else check if chunk is url $color_to_draw = is_a_url($chunk) ? $linkcolor : $black; //wrap based on image size if(strlen($chunk) > $image_width) { // if there is already a word in the current line make the first bit $imagewidth - current line width if ($start_x > $image_width -10) { $start_bit = substr($chunk, 0, ($image_width - $start_x)); $chunk = str_replace($start_bit, '', $chunk); } $chunkbits = wordwrap($chunk, $image_width, '\n', true); $chunkbits = explode('\n', $chunkbits); if($start_bit) { array_unshift($chunkbits, $start_bit); } // loop bits and draw them foreach ($chunkbits as $bit) { if($end_x + $bit > $image_width){ $start_x = 5; $start_y += 20; } $coords = imagettfbbox($fontsize, $angle, $font, $bit); $end_x = $coords[0] + $coords[4] + 10; imagettftext($im, $fontsize, $angle, $start_x, $start_y, $color_to_draw, $font, $bit); $start_x += $end_x; } unset($chunkbits); } else { if($end_x + $chunk > $image_width){ $start_x = 5; $start_y += 20; } $image_width = $image_width - 10; $coords = imagettfbbox($fontsize, $angle, $font, $chunk); $end_x = $coords[0] + $coords[4] + 10; imagettftext($im, $fontsize, $angle, $start_x, $start_y, $color_to_draw, $font, $chunk); $start_x += $end_x; } }
  2. I can't use css or html because I am outputting as an image with the imagettftext. So I am not sure the method you are using will work as it uses <br />. The image is a fixed width defined already with $image_width = 400; if that changes anything.
  3. How can I test if a chunk exceeds the image size and wrap that text to the next line. Not sure if I am even doing this correctly with my if statement. $text="Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem http://somelongurl.com/then-we-make-it-super-long-with-some-more/ Lorem Ipsum Lorem Ipsum Lorem Ipsum http://www.anotherlinks.com/"; $string_chunks = explode(' ', $text); foreach ($string_chunks as $chunk) { if($end_x + $chunk > $image_width){ $start_x = 5; $start_y += 20; } $coords = imagettfbbox($fontsize, $angle, $font, $chunk); $end_x = $coords[0] + $coords[4] + 10; $color_to_draw = is_a_url($chunk) ? $linkcolor : $black; imagettftext($im, $fontsize, $angle, $start_x, $start_y, $color_to_draw, $font, $chunk); $start_x += $end_x; } With this code I get: Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem http://somelongurl.com/then-we-make-it-super-long-with-some-more/ Lorem Ipsum Lorem Ipsum Lorem Ipsum http://www.anotherlinks.com/ What I would like to happen is something like: Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem http://somelongurl.com/then-we -make-it-super-long-with-some-more/ Lorem Ipsum Lorem Ipsum Lorem Ipsum http://www.anotherlinks.com/
  4. Here is the script the reads a twitter xml feed and generates a png from the first tweet. What I want to be able to is specify a width so the text will wrap and be able to position the text within a certain dimensions. I created the files with a base image because I didn't know how to create an image with a specific color. So removing the base image section would be great. Lastly, I would like to style the font with a certain font and weight. <?php // Get the XML data from Feedburner $sxe = new SimpleXMLElement('twitter.xml', NULL, TRUE); $tweet = $sxe->status[0]->text; // Create the image from the base image $img = imagecreatefrompng('tweet-base.png'); $color = imagecolorallocate($img, 0x33, 0x33, 0x33); imagestring($img, 2, $xpos, 2, $tweet, $color); // Save the image imagepng($img, 'tweet.png'); ?>
  5. The first one worked and then I get the error A PHP Error was encountered Severity: Warning Message: Division by zero
  6. This does not seem to work, throws a syntax error.
  7. Maybe this will help, here is the section of the file I am working on. I want to enter the percentage just before the % sign. <h3>Popular Tags</h3> <ul class="chartlist"> <?php foreach($popular_tags as $tag): ?> <li><a href="<?php echo $this->config->item('base_url')?>items/tag/<?php echo $tag->slug?>"> <span class="label"><?php echo $tag->name?></span></a><span class="index" style="width: %"></span></li> <?php endforeach; ?> </ul>
  8. Each entry into the database is a single number, meaning 0 - ∞
  9. $tag have 4 elements, tag_id, name, slug, count. Count is the one I am after and it stores the number of tags 0 - the highest number.
  10. I am a noob to php and just trying to customize something so I am not really sure how to get the array of numbers. If you could throw some knowledge my way it would be much appreciate.
  11. What if I wanted to do this for numbers in a mysql table, would I just replace the numbers in the array with the table name? Like... <?php $numbers = array($tag->count); $outof = max($numbers); foreach ($numbers as $number) { echo "$number: " . (($number / $outof) * 100) . "\n<br />"; } ?> Didn't seem to work to work for me.
  12. I am looking to show percentages relative to the highest value in the list—so there is always at least one 100% and everything else is a percentage of that maximum value. How would I go about doing this?
  13. Here is all the code. This is a photo gallery that uses the date to order the pictures. Let say there are 3 picture. When you are on 3 and use $lastpage it goes to ?pg=4 instead of the begeinning ?pg=1. [code]<? $Files = array(); $Files[] = ""; $dirfiles =  opendir($dir); $imgcount = 1; $cdate = date("Ymd"); $pg = $_GET['pg']; if (! $dirfiles) die('Can Not Find Any Images' . $dir); while ($Filename = readdir($dirfiles)) {     if($datedriven == true) {$fulldate = substr($Filename, 0, 8); }else{$fulldate = 0;}     $fulldate = substr($Filename, 0, 8);     if ($Filename == '.' || $Filename == '..' || $fulldate > $cdate)     continue;     $imgcount++;     $Files[] = $Filename; } sort($Files); $imgcount = $imgcount-1; if($pg == "" or $pg > $imgcount or $pg < 1){ $pg = $imgcount; } $imagesource = $dir . $Files[$pg]; $imageinfo = getimagesize($imagesource); $imageheight = $imageinfo[1]; $imagewidth = $imageinfo[0]; if($datedriven == true) {     $month = substr($Files[$pg], 4, 2);     $day = substr($Files[$pg], 6, 2);     $year = substr($Files[$pg], 0, 4);     $imagecolor = "#" . substr($Files[$pg], 12,6); }else{     $month = "";     $day = "";     $year = "";     $imagecolor = $defaultbackcolor; } $lastpage = $pg +1; if($lastpage < 1){ $lastpage = $imgcount; } $nextpage = $pg -1; if($nextpage < 1){ $nextpage = $imgcount; } ?>[/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.