简体   繁体   中英

How can I determine the “bytes per row” of a PNG image in php?

I need to know the bytes per row of a PNG image in order to use the ^DY command in ZPL. I am using PHP to generate the ZPL commands. I have a script that reads the hex data and total bytes from the PNG which is sent to my printer with the ^DY command -- but the image will not print unless I also provide the "bytes per row" of the image. How might I obtain this?

I was thinking that "bytes per row" might be the total bytes in one row of pixels so I tried using (total bytes)/(width in pixels) but this does not seem to work.

If you know it's an image, you can use getimagesize . It returns an array of information, of which the first two are the width and height of the image. This will work on other supported image types, as well.

$info = getimagesize($file);

If you need more information about the file, take a look at fileinfo .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM