Archive

Author Archive

iPhone nano

February 15th, 2009 jigish No comments

iphone nano iphone shuffle1 iPhone nano

While analysts have been speculating that Apple may unleash a smaller (and cheaper) handset in the not too distant future in order to grab a sect of market share not interested in the relatively pricey iPhone, the rumors are seeming to gain traction. According to Kevin Chang, a JP Morgan analyst based in Taiwan, Apple is actually looking to “launch a cheaper version of the iPhone in the fourth quarter that could be based on its iPod nano music player.” The report cited anonymous sources “in the supply channel” and also referenced the now-famed patent that suggests such a device could be materializing. Still, we’d highly recommend taking all of this in with a healthy heap of salt for the time being, but don’t be incredibly shocked if your next iPod nano unexpectedly rings while you’re stereotypically browsing through Gorillaz tracks

How to create bar graph with dynamic scaling

October 18th, 2008 jigish No comments

Hi everyone, this tutorial will help you in creating a bar graph from PHP with the ability to adjust the scale depending upon the values provided. The technique used is smart enough to handle the number and range of values. A preview of the graph is shown below

Graph

All you need to understand this tutorial is the knowledge of following PHP image functions

* imagecreate
* imagecolorallocate
* imagefilledrectangle
* imageline
* imagestring
* imagepng

in addition the following PHP functions are also used and offcourse some mathematics as well

* count
* intval
* list
* each
* header

If you have a good understanding of all these function, its good to go otherwise you should click on function which is new to you to consult the documentation and get back after learning all these functions

Lets get started

First of all declare an array of values for the graph. Declare these values in the form of associative array (i.e key and value pairs). Keys will be shown at the bottom as the graph legend and the values will be used to draw bars.

$values=array(
"Jan" => 110,
"Feb" => 130,
"Mar" => 215,
"Apr" => 81,
"May" => 310,
"Jun" => 110,
"Jul" => 190,
"Aug" => 175,
"Sep" => 390,
"Oct" => 286,
"Nov" => 150,
"Dec" => 196
);

Now define the size of image, i have used an image of size 600×400 for this tutorial.

$img_width=600;
$img_height=400;

The graph we are going to create has a border around it, i have declared a variable $margins to create that border around the four sides.

$margins=20;

Now find the size of graph by subtracting the size of borders.

$graph_width=$img_width - $margins * 2;
$graph_height=$img_height - $margins * 2;

Create an image of the size defined above

$img=imagecreate($img_width,$img_height);

Define the width of bar. Gap between the bars will depend upon the width and number of bars and the gaps will be one more than the total number of bars as there is gap on the right and left of the graph. You can see in our example, we have 12 bars but 13 gaps, thats why you see ($total_bars+1) in the denominator.

$bar_width=20;
$total_bars=count($values);
$gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);

Define colors to be used in the graph

$bar_color=imagecolorallocate($img,0,64,128);
$background_color=imagecolorallocate($img,240,240,255);
$border_color=imagecolorallocate($img,200,200,200);
$line_color=imagecolorallocate($img,220,220,220);

Create a border around the graph by filling in rectangle

imagefilledrectangle($img,1,1,$img_width-2,$img_height-2,$border_color);
imagefilledrectangle($img,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);

Now the maximum value is required to adjust the scale. Ratio is calculated by dividing graph height by maximum graph value. Each value will be multiplied with ratio, so that no bar goes beyond the graph height.

$max_value=max($values);
$ratio= $graph_height/$max_value;

Drawing horizontal lines is optional, note that the margin variable is subtracted from image height so that first line is positioned inside the graph area (Discarding the margins). If you have trouble understanding this code, use a paper and pencil to manually find the values of variable at each repitition of the loop

$horizontal_lines=20;
$horizontal_gap=$graph_height/$horizontal_lines;
for($i=1;$i<=$horizontal_lines;$i++){
$y=$img_height - $margins - $horizontal_gap * $i ;
imageline($img,$margins,$y,$img_width-$margins,$y,$line_color);
$v=intval($horizontal_gap * $i /$ratio);
imagestring($img,0,5,$y-5,$v,$bar_color);
}

Here comes the most crucial part of our graph, drawing the bars. Each of the 8 lines in the for loop are individually explained below

1. Extract key and value pair from the current pointer position, each iteration of loop moves the internal pointer of array to the next entry
2. The x1 value (i.e. left) of each bar gets and increment by $gap+$bar_width with each iteration of loop
3. The x2 value (i.e. right) is calculated by adding bar width with x1
4. y1 is the top of each bar. ratio is multiplied with individual values to mare sure that bars remain inside the graph boundries.
5. y2 (i.e bottom) is fix for all bars. Can also be placed outside the loop
6. Draw the graph with calculated left, top, right and bottom positions
7. The numeric value of each bar is shown at the top. Some plus or minus will be required to center align the displayed value with the bar
8. Display the legend i.e. Month names

for($i=0;$i< $total_bars; $i++){
list($key,$value)=each($values);
$x1= $margins + $gap + $i * ($gap+$bar_width) ;
$x2= $x1 + $bar_width;
$y1=$margins +$graph_height- intval($value * $ratio) ;
$y2=$img_height-$margins;
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
imagestring($img,0,$x1+3,$y1-10,$value,$bar_color);
imagestring($img,0,$x1+3,$img_height-15,$key,$bar_color);
}

Show the graph as a png image

header("Content-type:image/png");
imagepng($img);

The whole script is givenbelow, just copy and enjoy your own php graphs

 110,
"Feb" => 130,
"Mar" => 215,
"Apr" => 81,
"May" => 310,
"Jun" => 110,
"Jul" => 190,
"Aug" => 175,
"Sep" => 390,
"Oct" => 286,
"Nov" => 150,
"Dec" => 196
);

$img_width=450;
$img_height=300;
$margins=20;

# —- Find the size of graph by substracting the size of borders
$graph_width=$img_width - $margins * 2;
$graph_height=$img_height - $margins * 2;
$img=imagecreate($img_width,$img_height);

$bar_width=20;
$total_bars=count($values);
$gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);

# ——- Define Colors —————-
$bar_color=imagecolorallocate($img,0,64,128);
$background_color=imagecolorallocate($img,240,240,255);
$border_color=imagecolorallocate($img,200,200,200);
$line_color=imagecolorallocate($img,220,220,220);

# —— Create the border around the graph ——

imagefilledrectangle($img,1,1,$img_width-2,$img_height-2,$border_color);
imagefilledrectangle($img,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);

# ——- Max value is required to adjust the scale ——-
$max_value=max($values);
$ratio= $graph_height/$max_value;

# ——– Create scale and draw horizontal lines ——–
$horizontal_lines=20;
$horizontal_gap=$graph_height/$horizontal_lines;

for($i=1;$i<=$horizontal_lines;$i++){
$y=$img_height - $margins - $horizontal_gap * $i ;
imageline($img,$margins,$y,$img_width-$margins,$y,$line_color);
$v=intval($horizontal_gap * $i /$ratio);
imagestring($img,0,5,$y-5,$v,$bar_color);

}

# ———– Draw the bars here ——
for($i=0;$i< $total_bars; $i++){
# —— Extract key and value pair from the current pointer position
list($key,$value)=each($values);
$x1= $margins + $gap + $i * ($gap+$bar_width) ;
$x2= $x1 + $bar_width;
$y1=$margins +$graph_height- intval($value * $ratio) ;
$y2=$img_height-$margins;
imagestring($img,0,$x1+3,$y1-10,$value,$bar_color);
imagestring($img,0,$x1+3,$img_height-15,$key,$bar_color);
imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
}
header("Content-type:image/png");
imagepng($img);
$_REQUEST['asdfad']=234234;

?>

Sony’s Latest OLED TV Prototype Is 1 Millimeter Thin

October 6th, 2008 jigish No comments

Sony has unveiled a prototype OLED (organic light emitting diode) television that’s less than a millimeter thin — that’s one third the thickness of its current OLED television and a tenth that of its thinnest LCD (liquid crystal display) set.

The TV measures just 0.9mm and is based on a prototype 0.3mm screen that Sony first showed earlier this year. The prototype set was on show at the Ceatec 2008 electronics expo in Japan and attracted a steady stream of curious attendees, with many of them snapping pictures of it.

Read more…

How works the OLED technology?

October 6th, 2008 jigish No comments

We give you overview for the organic light emitting technology!

OLED (“Organic light emitting diodes”) displays are considered as the screens of the future.

Read more…