In a food and beverage system, first use PHP to generate a good order ticket, and then stored in the directory. The Python script periodically detects the directory and passes it to the printer when there is a picture.
Now encountered a problem is that the PHP generated image is to specify the width of the high, but some orders more or less dishes, resulting in the length of the order ticket content is different, in PHP how to generate a picture of fit content? Think for a long time have no clue, please help.
Reply content:
In a food and beverage system, first use PHP to generate a good order ticket, and then stored in the directory. The Python script periodically detects the directory and passes it to the printer when there is a picture.
Now encountered a problem is that the PHP generated image is to specify the width of the high, but some orders more or less dishes, resulting in the length of the order ticket content is different, in PHP how to generate a picture of fit content? Think for a long time have no clue, please help.
Can be used imagettfbbox
to get the width height of the bounding rectangle generated by the specified text under the TTF font
It's easy to assume that a blank menu picture has a minimum length of 10cm, a dish, and a 1cm image length. When generated, calculate how many items are in the menu.
Then the length will be adaptive.
Picture length = Minimum length + number of items * length to be added per item
Calculate the height before generating the picture.