Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP JQuery to convert number to image

Posted on 2014-02-01
11
Medium Priority
?
661 Views
Last Modified: 2014-02-03
Does anyone know if a piece of javascript, JQuery or PHP that can convert a number into an image?  It is for a visual that represents total money raised, like a thermometer?
0
Comment
Question by:rgranlund
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39826735
This article, while not exactly on point, shows how PHP renders string characters as images.  I'll try to find you a code sample, too.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_9849-Making-CAPTCHA-Friendlier-with-PHP-Image-Manipulation.html

Also, fair warning - I have never tested this, but it might be promising.
http://plugins.jquery.com/thermometer/
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39826784
You can use this image script as the src= attribute of the <img> tag.  Just give it the n= argument, and away you go!  Experiment with it to get the look and feel you want.

See http://www.laprbass.com/RAY_temp_rgranlund.php?n=1024

<?php // RAY_temp_rgranlund.php
error_reporting(E_ALL);

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28354076.html

// GET THE NUMBER FROM THE URL ARGUMENT "n="
$num = isset($_GET['n']) ? $_GET['n'] : FALSE;
if ($num === FALSE){
    trigger_error("MISSING URL ARGUMENT n=", E_USER_ERROR);
}

// ADJUST THIS FOR YOUR NEEDS
$str = str_pad(number_format($num),8, ' ', STR_PAD_LEFT);

// ADJUST ALL OF THESE FOR YOUR NEEDS, TOO
// CREATE THE IMAGE RESOURCE
$img = imageCreateTrueColor
( 200     // WIDTH
, 60      // HEIGHT
)
;
// WHITE BACKGROUND COLOR
$bgc = imageColorAllocate
( $img   // IMAGE RESOURCE
, 255    // RED
, 255    // GREEN
, 255     // BLUE
)
;
// FIREY RED TEXT COLOR
$txt = imageColorAllocate
( $img   // IMAGE RESOURCE
, 233    // RED
, 14     // GREEN
, 91     // BLUE
)
;
// PAINT THE BACKGROUND
imageFill
( $img   // IMAGE RESOURCE
, 0      // X-OFFSET
, 0      // Y-OFFSET
, $bgc   // FILL COLOR
)
;
// WRITE THE TEXT
imageString
( $img   // IMAGE RESOURCE
, 5      // FONT (SEE THE MAN PAGE)
, 0      // X-OFFSET
, 0      // Y-OFFSET
, $str   // THE STRING DATA
, $txt   // THE TEXT COLOR
)
;
// SEND THE IMAGE INTO THE BROWSER OUTPUT STREAM
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);

Open in new window

HTH and best regards, ~Ray
0
 
LVL 9

Expert Comment

by:rinfo
ID: 39827406
This is also a good option
http://www.daftlogic.com/projects-text-to-image.htm
have tested it earlier and work quite well
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39827662
@rinfo: I tested the daftlogic script and was unable to get it to work.  It looks like something left over from PHP4 days (no class constructor, use of "var" keyword, etc).  Can you please post a working example?   Thanks, ~Ray
0
 
LVL 9

Expert Comment

by:rinfo
ID: 39827702
Hello Ray
I am submitting code that i have used.
I have used it as it is.
And i am also submitting snapshot of output.
txt2image.php
txt2image.png
0
 
LVL 9

Expert Comment

by:rinfo
ID: 39827704
I have php 5.4 installed as of now.
0
 
LVL 9

Expert Comment

by:rinfo
ID: 39827706
Of course it would require a fonts directory with times.ttf in it .
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39828024
Great, thanks for posting that ~Ray
0
 
LVL 44

Expert Comment

by:Chris Stanyon
ID: 39829121
If you want a thoroughly modern approach, then you could always use the HTML5 Canvas element and draw your thermometer directly using jQuery :)
0
 
LVL 7

Author Closing Comment

by:rgranlund
ID: 39830410
This answer led me to what I was trying to discover.  Thank you.  However, I will be looking at the rest of the answers soon.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39830421
Thanks for the points and thanks for using EE.  And good luck with your project, ~Ray
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question