Jump to content

Graphics Problem: How to draw a really smooth line with PHP


ExpertAlmost

Recommended Posts

 

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!

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.