ExpertAlmost Posted September 11, 2009 Share Posted September 11, 2009 When using PHP to draw lines or rectangles that are neither horizontal nor vertical, the lines are not smooth. Are there any tricks to getting a really fine-grained, smooth, angled-line in PHP? As a work-around, I have drawn hundreds of shapes in Corel Draw and exported them as transparent-background PNG files. When I need a shape, I overlay them onto my PHP created image. Which means I have hundreds of static, uniquely named graphics files. There has to be a better way! Why can I draw and import a smooth-lined rectangle from Corel but can't draw a rectangle as smoothly with PHP? Soon I will have to change graphic sizes forcing me to redraw and resave all those static images. Nightmare! Being able to dynamically draw my images in PHP would be magnificent. Any and all insights are greatly appreciated. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/173861-graphics-problem-how-to-draw-a-really-smooth-line-with-php/ Share on other sites More sharing options...
RussellReal Posted September 11, 2009 Share Posted September 11, 2009 I am not exactly sure what you mean by non-smooth lines.. to me they look smooth >.> what you could probably do if you're that interested.. create the horizontal line (which appears smooth for you - whatever that means) inside 1 image resource.. and than resize/rotate it and copy it into the MAIN image Quote Link to comment https://forums.phpfreaks.com/topic/173861-graphics-problem-how-to-draw-a-really-smooth-line-with-php/#findComment-916517 Share on other sites More sharing options...
ExpertAlmost Posted September 11, 2009 Author Share Posted September 11, 2009 Thank you for your reply Russell! I had wondered about that option. I am thinking that that might be why my rectangular arrows from Corel look great at small angles off the horizontal while the PHP lines are so jagged. Have you tried that option? If I create a PNG in PHP, will it behave the same as a PNG with transparent background created in a graphics program? I have had problems in the past wth overlaying one PHP-created graphic onto another... In detail, are you suggesting creating a very large retangular arrow, for example, in PHP, then resizing it to half size using imagecopyresized? Then doing a second image copy using imagelayereffect = overlay? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/173861-graphics-problem-how-to-draw-a-really-smooth-line-with-php/#findComment-916524 Share on other sites More sharing options...
RussellReal Posted September 11, 2009 Share Posted September 11, 2009 in php you need to play with imagecolorallocatealpha to create a transparent color, then fill it in the background, because for each image resource the background color is the FIRST color allocated.so if you allocate a transparent color you're more likely to have a transparent background.. ALSO, you need to use different copy functions to merge them imagecopymerge don't shrink the images.. just create a new images with the width/height requirements for that particular image and then merge the two.. Quote Link to comment https://forums.phpfreaks.com/topic/173861-graphics-problem-how-to-draw-a-really-smooth-line-with-php/#findComment-916830 Share on other sites More sharing options...
bossman Posted September 11, 2009 Share Posted September 11, 2009 what are you guys talking about? i dont understand what you mean by your trying to 'draw lines with php' ? Quote Link to comment https://forums.phpfreaks.com/topic/173861-graphics-problem-how-to-draw-a-really-smooth-line-with-php/#findComment-916896 Share on other sites More sharing options...
thebadbad Posted September 11, 2009 Share Posted September 11, 2009 Have a look at imageantialias(). @bossman We're talking PHP GD. Quote Link to comment https://forums.phpfreaks.com/topic/173861-graphics-problem-how-to-draw-a-really-smooth-line-with-php/#findComment-916904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.