Web Development Information |
PIM Team Case Study: Creating Text Effects With PHP and GD
See how you can create graphic effects on text with PHP and GD - drop shadows, arcs, fonts and colors. Problem A-tec Signs and Sraphics Inc. launched a web site with the idea to sell decals online. To achieve better customers ineterest the website had to integrate online decal builder. The company is offering also decals for vehicles which brought some specific requirements to the builder like having the decal text turning arround 4 types of arcs. Goals
Solution Because of the need for increasing customers interest we had to think about not for perfect math formulas when showing the graphs in the preview area, but for the people who will look at them. As we will reaveal below, there were few problems going arround human appreceptions for something 'perfectly smooth' and the matchematical perfect figures. Methodology We were going to extensively use PHP GD library for the text effects. It provided easy changing of fonts and colors, adding drop shawdows and rotating the texts. We had also to create color palletes which to appear when user click and disappear when color is selected (You can personally try the decals creating here). Using hidden layers and javascript was supposed to do the work. The main problem in this site was to create 4 types of arcs so when the user selects one of them the text is created arround imaginary arc (like in the vector graphical softwares). We were going to study Bezie's formulas and create these arcs with its help. Implementation PIM Team Bulgaria had the task to build the full functional online decals builder with the following features: - Decal background Some users were supposed to have their decals placed on colored background. We had to allow the preview area to be painted in a selected background. First we created the image in temp folder: // the name of destination image $dest='decals/'.time().'.jpg'; //the background imagefilledrectangle ( $im, 0, 0, 590, 60, $colors[$_POST['bcolors']]); $colors array contains the available color which are stored by the administrator in the database. Thus, when the visitor selects a background it is passed as parametter to imagefilledrectangle function. - Font selection Users should be able to select fonts for their future decals. Knowing that we can't consider all the fonts will be available on all visitor's computers we had to upload them on the web server directory. We allowed the admin to manage the fonts, adding their names and uploading files in admin area. The fonts in the select box came from the database. Selected font was passed in the call to imagettftext funtion which is drawing on the previously created image. - Color Selections The color selections had to be a palettes which appear when user clicks and disappear when color is selected. The palette had to look as a table with colors and these colors are also defined in the admin area so they had to come dynamicly. We had to seed a static javascript function with dynamic content. We created a PHP cycle which was taking the colors from the database and then creating a string for HTML table. This table is then passed to a javascript function which creates the palletes with the help of hidden layers: function showTable(table) { mouseX = window.event.x + document.body.scrollLeft+25; if(table=='background') { var content=""; var y=460; } if(table=='fonts') { var content=""; var y=690; } if(table=='shadows') { var content=""; var y=810; } document.getElementById('tabler').style.pixelLeft=mouseX; document.getElementById('tabler').style.pixelTop=y; document.getElementById('tabler').style.visibility='visible'; document.getElementById('tabler').innerHTML=content; } Of course, once the user select the desired color we had to hide the pallette: function setColor(elid,color,fromid,shc) { document.getElementById(elid).value=color; document.getElementById('tabler').style.visibility='hidden'; } Thus we created nice palettes which appear and disappear on a single click and don't take much space on the screen. - Drop Shawdows The decals offered has the ability to have a drop shadow added so we had to add this option to the online builder. PHP however didn't offered a nice function for that. We created a procedure which draws the texts twice - once the original 100% saturated text and once the shadow with a percentage of the color and appropriate displacement. Of course the shadow was drawn on the image before the main text. @imagettftext($img, 20, $gr[$i], $x+$dx, $ys[$i]+$dy, $scolors[$shadowcolor], "fonts/".$_POST['fonts'],$word[$i]); - Arcs The main problem came when we had to 'rotate' the texts thru arcs. First we created perfect Bezie funtion which to draw the curves and adjust the letter above them. But what a surprise - the curves looked perfect alone, but when we adjusted the letters above them they seemed rough. After studying this problem we realised that the rough screen resolution and the disability to antialise the images wouldn't allow us to create nice arcs. We were standing against insoluble problem. We decided to create few arcs with a graphical software (CorelDraw) and to see what could be wrong. We noticed that Corel's curves were looking great after they are manually adjusted. However you can't just leave the program to create perfect curves automaticly. A human eye was needed to judge when a curve looks right and when not. We got a totally different direction. There wasn't an universal function to help us. The solution we found was to 'manually' adjust each letter. We created a procedure with cases which were adjusting each letter on the appropriate place and with appropriate rotation depending on how long was the text. It worked! We created 2 arrays for each arc type - one array with the positions and one array with the rotations. The rest was simple: if($arctype) { $start=(35-$l)/2; if($start%2) $start+=1; $gr=array_slice($gr,$start,$l); $ys=array_slice($ys,$start,$l); } if(!$arctype) { $ys=array(); $gr=array(); //making the arrays for($i=0;$i You can go on the atec's site and try the arcs we achieved (http://atecsigns.com/decal/step_1.php). Results Now A-tec Sings's web builder creates perfect decals with graphs, calculates the price and allows you to add the decals to your shopping cart and chgeckout (the shopping cart software is also created by PIM Team Bulgaria). The builder allows the visitor to create the desired decals with any color, dropped shadow, background and shape, to preview it and to calculate the cost for different sizes and quantities. The website and builder were promoted with massive radio advertising company. At that time it was the only decal builder which allowed creating texts arround arcs. Conclusions
About The Author Bobby Handzhiev is a senior developer in PIM Team Bulgaria
MORE RESOURCES: Unable to open RSS Feed $XMLfilename with error HTTP ERROR: 404, exiting |
RELATED ARTICLES
Streamline your Business Website with a Content Management System I talk with so many people who have small businesses and would like to have a web presence but don't know the first thing about how to even get started. Some of the reasons I hear are:- I don't know how to build a website. Get a Website!, Register Your Domain!: To Website or Not to Website? If you're fairly new to the Internet scene, you may just be a bit overhelmed with family members, friends, collegues, and advertisements urging you to get your own website for your business. Typically, this is good advice for businesses. Are You Being Scammed By Your Web Design Company? This is a growing concern amongst many business owners. Does your web design company own you? This may be possible if you've allowed them to host your web site for you and also register your domain name for your company. New Years Resolutions: Is Improving Your Website One of Them? With the New Year upon us yet again, it's time to prepare for the successes of 2005. Did you watch with envy last year as your competitors dominated your industry? Do you think your site is doing just fine because no one has ever called to complain? Well here's some food for thought: 96% of all prospects will click over to your competitor if they encounter a problem on your website. But My Business Doesnt Need A Website! Revenues are often lost because many business owners don't see the value in having a website. They claim their products can't be sold online and technology is overwhelming. Why You Need A Web Site "I have a small business with just a couple of employees and I don't think my product can really be sold online. Do I need a web site?"In this day and time, there is very little that can't be sold over the Internet. Web Site Promotion: How To Advertise Your Website For Profits Making money with your web site is the dream and goal of millions of webmasters all over the internet including myself. In order to reach this goal you need a variety of web site promotions running all at the same time. Improve Conversion Rates - Effective Content Your site is fast and getting traffic, but conversion rates are disappointing. You may have problems with the tone of your contentDo You Believe?You must have passion for the product or service you are providing. How to Maximize the Value of Every Visitor to Your Website While most marketers are beginning to understand the critical importance of maximizing conversion rates, few are tracking or working to maximize another critical measurement of website effectiveness.Visitor value?Visitor value is simply a representation of how much money you make per visitor to your website. Cost Effective and Powerful Dynamic Websites w. Fantastico Web Hosting If you are developing your website on a host that charges less that $5 a month, make plenty of backups as you are likely to loose your website files when the webhost goes out of business without notice. Indeed, be extremely wary of any such host. Planning A Usable Website: A Three-step Guide A website is like an information flow, with you as the provider and your site visitors as the receivers of the information. If you don't plan your website with this in mind right from the start, you could find yourself with a brand new website that solves all your immediate needs. You Need a Website! No matter the size of your business, having a web site is a low cost way to market your services and products twenty-four hours a day. Web sites are a constant advertisement for your business and will help you reach your targeted customers effectively. Search Engines and Customers Want Focused Web Site Content How do you decide on the content, products and or services you will promote on your Web site.Or should I go back one step further and ask why did you decide to create a website in the first place. The Problem with Paypal On Your Web Page When I set up my website I felt paypal was a very simple and easy solution when people wished to purchase my products.For 6 months I was getting 150-200 unique visitors a day, and yet only a few sales every week. How to Get a Better Web Site ROI Better Web Site ROIHow to increase your business profitability by hundreds ofpercentWebsites are ubiquitous these days and everybody is trying toget a betterweb site ROI. With millions upon millions of sites all trying toappeal to the same traffic, what can you do to improve your website ROI?What's In A NameYou can use Google Adwords to very quickly and cost effectivelyimprove your business profitabilityby a significant amount - hundreds possibly thousands ofpercent. Beware the Software Siren I've heard several prominent web marketers mention in their classes and public forums how easy it is to create your own software. Why, all you have to do is run over to Elance. Nonsense! Why Do I Need a Website? "I don't sell anything online, I don't advertise online, in fact I don't really even know how to use a computer.. Building a Web Store on Shoestring Budget in less than Four Hours Starting a business online is no longer as difficult as it used to be! Now, there are plenty of interesting business ideas that anybody can pick up from various Internet resources. Startup related cost, which used to deter many in taking action, has become negligible. Successful Web Development: 10 Key Elements There are many elements that are key to successful web development. There is no arguing that elements of talent such as graphic design, writing, and technical expertise are important. Traffic for Webmasters "If you build it, they will come"; is an age old phenomenon for webmasters that they develop the website and visitors themselves would visit that. This may be true for only a handful of websites but the most important and crucial topic for any webmaster today is to how to get targeted traffic to his website. |
home | site map | contact us |