飞鹅标签机是支持打印图片的,不过只能识别黑色,灰色居然给忽略了,毕竟是热敏打印机,只能打印黑色,不知道是不是刚出来的原因,无论是官方的文档,还是提供的DEMO,都不是很完善,特别是打印图片的,只提供了PHP的DEMO。可惜小编是用Python写的,下面小编分享下,Python的案例:
注意:官方这么要求图片的:图片二进制数据,需配合标签使用,最佳效果为不大于224px的正方形(宽高都为8的倍数)黑白图,支持jpg、png、bmp,不能超过10K。 小编提醒大家:图片一定要用正方形的。

#coding:utf-8

import time
import hashlib
import requests
import io
from requests_toolbelt import MultipartEncoder

def printLabelMsg(qr_addredd, serial):
    # 初始化标签大小
    # content = '<SIZE>60,40</SIZE>'
    content = ""
    content += '<IMG x="200" y="30">'
    content += '<TEXT x="280" y="55" font="12" w="2" h="2" r="0">打印图片</TEXT>'
    STIME = str(int(time.time()))#不需要修改
    LOGO = "本地图片路径"
    params = {
        'user':******,
        'stime':*******,
        'sig':signature(STIME),
        'apiname':'Open_printLabelMsg',
        'sn':******,
        'content':content,
        'times': TIMES,
        'img': (LOGO, open(LOGO, 'rb'), 'application/jpeg')
    }
    m = MultipartEncoder(params)
    response = requests.post('http://api.feieyun.cn/Api/Open/', data=m,headers={'Content-Type': m.content_type}, timeout=30)
    code = response.status_code #响应状态码
    if code==200:
        con_str=str(response.content, encoding = "utf-8")  
        content=eval(con_str)
        if(content.get('ret')!=0):
            raise RuntimeError(con_str)
        print(response.content)#服务器返回的JSON字符串,建议要当做日志记录起来
    else:
        raise RuntimeError('code{}'.format(code))

下面小编提供下官方客服给的PHP的案例:

<?php


function printLabelMsg($user, $skey, $sn, $content, $times = 1)
{
    $url = 'http://api.feieyun.cn/Api/Open/';
    $stime = time();
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, [
        'user' => $user,
        'stime' => $stime,
        'sig' => sha1($user.$skey.$stime),
        'apiname' => 'Open_printLabelMsg',
        'sn' => $sn,
        'content' => $content,//这里就是配合使用的IMG标签
        'times' => $times,
        'img' => new \CURLFile('test.jpg')
    ]);
    $headers = array('Content-Type: multipart/form-data;');//传图
     curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
    $response = curl_exec($ch);
    curl_close($ch);

    var_dump( $response );
}

printLabelMsg('*************', '*******************', '**********', '<img x="50" y="10">');//USER,UKEY,打印机编号
Last modification:February 16, 2021
If you think my article is useful to you, please feel free to appreciate