generate qr code with bacon/bacon-qr-code not working - laravel-5

I tried using your sample code on both an existing image and a non-existing image .
Both case failed , and no image is generated on the latter.
first trial:
$renderer = new \BaconQrCode\Renderer\Image\Png();
$renderer->setHeight(256);
$renderer->setWidth(256);
$writer = new \BaconQrCode\Writer($renderer);
$writer->writeFile('Hello World!', 'qrcode.png');
i then thought i could just write string instead of writing into a file but when i echo i still don't get image
2nd trial :
`
$renderer = new \BaconQrCode\Renderer\Image\Png();
$renderer->setHeight(256);
$renderer->setWidth(256);
$writer = new \BaconQrCode\Writer($renderer);
$str= $writer->writeString('Hello World!');
header('Content-Type:image/png');
echo $str;`
i get the code below
�PNG IHDR�?1IDATx����n�0A'����kP!��؝9��������~������' �4�&�#�Hi M� �4�&�#�Hi M� �4�&�#�Hi M� �4�&�#�Hi M� �4�&�#�Hi M� �4����x�^���3:|������u�+W�_u?O��9�p�'��4�&�#�Hi#�W�Z'^��?m=������|�Hi M� �4�6zpeպ�u�U�럾N?����<Hi M� �4�&Ҏ����#�'i M� �4�&�#�9�F�� ��<Hi M� �4�&Ҏ�L[/�v?w�~�?� #�Hi M� �4�6z0�|�?�>�~A�|���!M� �4�&�#�H�*���}��� M� �4�&�#�H����S_��������w'�� #�Hi M� �4�6b���u�����Ͽ�I�&�#�Hi M����~��u�Lx�<�^�����i M� �4�&�F�V�ǯz��ʴu��s�Us���Y�Q�0�&�#�Hi m�9�������U��w�|J� �4�&�#�H18�)�ᄒs��0 M� �4�&�#ڈ9���v���G�>E����̓M#�Hi M� ���\������<�������'i M� �4�&�#��9�����=��)� �'i M� �4�&�#ڑs�iv��?��?�'i M� �4�&�#�9�FO�{�j>P�3x�&�#�Hi M�98e�yչ����_�sw��>��4�&�#�Hi m����kv��OX��F�Hi M� �4��5y�v� M� �4�&�#�Hi M� �4�&�#�Hi M� �4�&�#�Hi M� �4�&�#�Hi M� �4�&�#�Hi M� ���mF�sE�}IEND�B�
What's the problem ?
any help ?

If you encode the output of the writeString to base64 you can then use it to show a base64 image in HTML.
use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;
$renderer = new ImageRenderer(
new RendererStyle(200),
new ImagickImageBackEnd()
);
$writer = new Writer($renderer);
$qr_image = base64_encode($writer->writeString($string));
And show it as an image like this.
<img src="data:image/png;base64, <?php echo $qr_image; ?> " />

I finally decided to use the package simpleqr-code .
link here :https://www.simplesoftware.io/docs/simple-qrcode

Related

What's wrong with Windows Task Sheduler + pytesseract + multiprocessing?

Have the python code with pytesseract & multiprocessing. When I start the code manually from PyCharm it works fine with any number of threads. When I start the code with Win Task Sheduler with 'threads=1' it works fine.
However if I start the code with Win Task Sheduler with 'threads=2' or more than 2, it finishes without processing the images and without any errors.
I've got log messages like this. Script starts but does nothing and there is no any errors in Win logs
2020-05-24 13:09:31,834;START
2020-05-24 13:09:31,834;threads: 2
2020-05-24 13:10:31,832;START
2020-05-24 13:10:31,832;threads: 2
2020-05-24 13:11:31,851;START
2020-05-24 13:11:31,851;threads: 2
Code
from PIL import Image
import pytesseract
from pytesseract import Output
import datetime
from glob import glob
import os
import multiprocessing as multiprocessing
import cv2
import logging
def loggerinit(name, filename, overwrite):
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
# create the logging file handler
fh = logging.FileHandler(filename, encoding = 'UTF-8')
formatter = logging.Formatter('%(asctime)s;%(message)s')
fh.setFormatter(formatter)
# add handler to logger object
logger.addHandler(fh)
return logger
def getfiles(dirname, mask):
return glob(os.path.join(dirname, mask))
def tess_file(fname):
img = cv2.imread(fname)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
im_for_T = Image.fromarray(img)
pytesseract.pytesseract.tesseract_cmd = 'C://Tesseract-OCR//tesseract.exe'
TESSDATA_PREFIX = 'C:/Program Files/Tesseract-OCR/tessdata'
try:
os.environ['OMP_THREAD_LIMIT'] = '1'
tess_data = pytesseract.image_to_osd(im_for_T, output_type=Output.DICT)
return fname, tess_data
except:
return fname, None
if __name__ == '__main__':
logger = loggerinit('tess', 'tess.log', False)
files = getfiles('Croped', '*.jpg')
t1 = datetime.datetime.now()
logger.info('START')
threads = 2
logger.info('threads: ' + str(threads))
p = multiprocessing.Pool(threads)
results = p.map(tess_file,files)
e = []
for r in results:
if type(r) == type(None):
e.append('OCR error: ' + r)
else:
print(r[0],". rotate: ",r[1]['rotate'])
p.close()
p.join()
t2 = datetime.datetime.now()
delta = (t2 - t1).total_seconds()
print('Total time: ', delta)
print('Files: ', len(files))
logger.info('Files: ' + str(len(files)))
logger.info('Stop.' + 'Total time: ' + str(delta))
# Print error if exist
for ee in e:
print(ee)
Whats wrong? How can I fix this issue?

QPixmap width and height return 0

problemPicture
ENV
Win10
python3.7
PyQt5
Desc
With the following code, where image_path is the absolute path to problemPicture.(this is not a question about cannot find the pic)
pixmapHight and pixmapWidth will get 0, but the picture can be well openned and viewed with default APP
And for most pictures, this code works well, but fail on this special one.
so can anyone explain it and give me some advice?
pixmap = QPixmap(image_path)
pixmapHight = pixmap.height()
pixmapWidth = pixmap.width()
PS this question seems the same, but the answer is not accepted, and neither to my question.
I find it is caused by wrong suffix.
The pic saved locally is suffixed by .png, but the real format is jpg.
When specifying with right format, eg: QPixmap(image_path, format = 'jpg'), I can get correct height and width.
here is my sample code to check real format:
import os
import sys
import imghdr
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
class DemoApp(QMainWindow):
def is_type_wrong(self, path):
current_type = path[path.rfind('.')+1:]
real_type = 'xxx'
if path.lower().endswith('.gif') or path.lower().endswith('.jpg') or path.lower().endswith('.png'):
header = []
with open(path, 'rb') as f:
while(len(header) < 5):
header.append(f.read(1))
print(header)
if (header[0] == b'\x47' and header[1] and b'\x49' and header[2] == b'\x46' and header[3] == b'\x38'):
real_type = 'gif'
if (header[0] == b'\xff' and header[1] == b'\xd8'):
real_type = 'jpg'
if (header[0] == b'\x89' and header[1] == b'\x50' and header[2] == b'\x4e' and header[3] == b'\x47' and header[4] == b'\x0D'):
real_type = 'png'
return current_type != real_type, real_type
def __init__(self, parent=None):
super(DemoApp, self).__init__(parent)
image_path_list = ['D:\FailPic.png', 'D:\OkPic.png', 'D:\FromWeb.jpg']
for image_path in image_path_list:
if os.path.exists(image_path):
fmt = imghdr.what(image_path)
if fmt == None:
# I get one picture still can be opened with default app while imghdr.what return None
isWrongType, real_type = self.is_type_wrong(image_path)
if isWrongType:
fmt = real_type
else:
print("!!! corrupted picture: %s" %image_path)
pixmap = QPixmap(image_path, format = fmt)
pixmapHight = pixmap.height()
pixmapWidth = pixmap.width()
print("[%s]isNull:%d pixmapHight: %f, pixmapWidth: %f, fmt: %s" %(image_path, pixmap.isNull(), pixmapHight, pixmapWidth, fmt))
else:
print("pic % not found" %(image_path))
if __name__ == "__main__":
app = QApplication(sys.argv)
main_window = DemoApp()
main_window.show()
sys.exit(app.exec_())

Anaconda/IntelPython doesn't seem to offload to Xeon Ph 30

>>> import numpy
>>> numpy.show_config()
mkl_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/home/steph/anaconda3/envs/intel_py/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/steph/anaconda3/envs/intel_py/include']
blas_mkl_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/home/steph/anaconda3/envs/intel_py/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/steph/anaconda3/envs/intel_py/include']
blas_opt_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/home/steph/anaconda3/envs/intel_py/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/steph/anaconda3/envs/intel_py/include']
lapack_mkl_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/home/steph/anaconda3/envs/intel_py/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/steph/anaconda3/envs/intel_py/include']
lapack_opt_info:
libraries = ['mkl_rt', 'pthread']
library_dirs = ['/home/steph/anaconda3/envs/intel_py/lib']
define_macros = [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)]
include_dirs = ['/home/steph/anaconda3/envs/intel_py/include']
>>>
Which seems to indicate that I have the correct libraries.
My env settings are:
export MKL_MIC_ENABLE=1
export OFFLOAD_DEVICES=1,2
export OFFLOAD_ENABLE_ORSL=1
export MKL_HOST_WORKDIVISION=0,2
export MKL_MIC_WORKDIVISION=1
export MKL_MIC_1_WORKDIVISION=0.9
export MKL_MIC_2_WORKDIVISION=0.9
#export MKL_MIC_MAX_MEMORY=<value>
#export MKL_MIC_<number>_MAX_MEMORY=<value>
#For example: export MKL_MIC_0_MAX_MEMORY=2G
export MKL_MIC_REGISTER_MEMORY=1
#export MKL_MIC_RESOURCE_LIMIT=<value>
#For example: export MKL_MIC_RESOURCE_LIMIT=0.34
#export MIC_OMP_NUM_THREADS=<value>
#export MIC_<number>_OMP_NUM_THREADS=<value>
#For example: export MIC_0_OMP_NUM_THREADS=240
export OFFLOAD_REPORT=2
#For example: export OFFLOAD_REPORT=2
#export LD_LIBRARY_PATH="/opt/intel/mic/coi/host-linux-release/lib:${LD_LIBRARY_PATH}"
#export MIC_LD_LIBRARY_PATH="/opt/intel/mic/coi/device-linux-release/lib:${MKLROOT}/lib/mic:${MIC_LD_LIBRARY_PATH}"
#export MKL_MIC_THRESHOLDS_?GEMM="<N>,<M>,<K>"
#For example: export MKL_MIC_THRESHOLDS_?GEMM="2000,1000,500"
export OMP_NUM_THREADS=16
export MIC_OMP_NUM_THREADS=236
export KMP_AFFINITY=granularity=fine,compact,1,0
export MIC_KMP_AFFINITY=explicit,granularity=fine,proclist=[1-236:1]
export MIC_ENV_PREFIX=MIC_
Yet, when I run an fft.py, the mismc indicates no activity on the Phis.
There is also no offload report.
Any idea what I'm doing wrong?
StackOverflow wants me to add more to the question before I can post. I have all the details in the post, so this is just fluff to see if I can get this to post. What a silly little AI bot.

Python 2.6 run time error

STEPCAFControl which is available in python2.6 but webgl module is not available. So I am trying to run this below program .
from __future__ import print_function
import sys
from OCC.STEPCAFControl import STEPCAFControl_Reader
from OCC.STEPControl import STEPControl_Reader
from OCC.IFSelect import IFSelect_RetDone, IFSelect_ItemsByEntity
from OCC.Display.SimpleGui import init_display
#from OCC.Display.WebGl import threejs_renderer
step_reader = STEPControl_Reader()
status = step_reader.ReadFile('./models/screw.step')
if status == IFSelect_RetDone: # check status
failsonly = False
step_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
step_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
ok = step_reader.TransferRoot(1)
_nbs = step_reader.NbShapes()
aResShape = step_reader.Shape(1)
print("Success")
else:
print("Error: can't read file.")
sys.exit(0)
display, start_display, add_menu, add_function_to_menu = init_display()
display.DisplayShape(aResShape, update=True)
start_display()
#my_renderer = threejs_renderer.ThreejsRenderer(background_color="#123345")
#my_renderer.DisplayShape(aResShape)
but getting this error.
How to solve this issue? Any suggestion?

Postfix server stopped sending external email

We have a postfix server running on MAC. Sometime yesterday our server stopped sending external email. We can send and receive internally, and we can receive from external. When we sent emails to other domains, though, they just disappear...
We've been working on this all day with no luck... Anyone have any thoughts?
Thanks!
--Charles
Here is our postconf -n
biff = no
command_directory = /usr/sbin
config_directory = /Library/Server/Mail/Config/postfix
content_filter =
daemon_directory = /usr/libexec/postfix
data_directory = /Library/Server/Mail/Data/mta
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin xxgdb $daemon_directory/$process_name $process_id & sleep 5
dovecot_destination_recipient_limit = 1
enable_server_options = yes
header_checks =
html_directory = /usr/share/doc/postfix/html
imap_submit_cred_file = /Library/Server/Mail/Config/postfix/submit.cred
inet_interfaces = all
inet_protocols = all
local_recipient_maps =
mail_owner = _postfix
mailbox_size_limit = 0
mailbox_transport = dovecot
mailq_path = /usr/bin/mailq
manpage_directory = /usr/share/man
message_size_limit = 20971520
mydestination =
mydomain = ourdomain.com
mydomain_fallback = localhost
myhostname = relay.ourdomain.com
mynetworks = 127.0.0.0/8 192.168.0.0/16 [::1]/128 [2001:240:587::]/64
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases
queue_directory = /Library/Server/Mail/Data/spool
readme_directory = /usr/share/doc/postfix
recipient_canonical_maps = hash:/Library/Server/Mail/Config/postfix/system_user_maps
recipient_delimiter = +
relayhost =
sample_directory = /usr/share/doc/postfix/examples
sendmail_path = /usr/sbin/sendmail
setgid_group = _postdrop
smtp_sasl_auth_enable = no
smtp_sasl_password_maps =
smtpd_client_restrictions = permit_mynetworks permit_sasl_authenticated permit
smtpd_enforce_tls = no
smtpd_helo_required = no
smtpd_helo_restrictions =
smtpd_pw_server_security_options = cram-md5,digest-md5,login,plain
smtpd_recipient_limit = 1000
smtpd_recipient_restrictions = permit_sasl_authenticated permit_mynetworks reject_unauth_destination permit
smtpd_sasl_auth_enable = yes
smtpd_tls_CAfile = /etc/certificates/relay.ourdomain.com.028E0388CA5957E50A13248BAD1711F41C84F596.chain.pem
smtpd_tls_cert_file = /etc/certificates/relay.ourdomain.com.028E0388CA5957E50A13248BAD1711F41C84F596.cert.pem
smtpd_tls_ciphers = medium
smtpd_tls_exclude_ciphers = SSLv2, aNULL, ADH, eNULL
smtpd_tls_key_file = /etc/certificates/relay.ourdomain.com.028E0388CA5957E50A13248BAD1711F41C84F596.key.pem
smtpd_use_pw_server = yes
smtpd_use_tls = yes
tls_random_source = dev:/dev/urandom
unknown_local_recipient_reject_code = 550
use_sacl_cache = yes
virtual_alias_domains = $virtual_alias_maps hash:/Library/Server/Mail/Config/postfix/virtual_domains
virtual_alias_maps = $virtual_maps hash:/Library/Server/Mail/Config/postfix/virtual_users
postconf: warning: /Library/Server/Mail/Config/postfix//main.cf: unused parameter: default_destination_recipient_limit:=1000
relay:~ localadmin$
Looks like the issue was being caused by a typo...
I kept getting the error:
unused parameter: default_destination_recipient_limit
Upon looking at the master.cf file, I found that it had:
default_destination_recipient_limit: = 1000
Note the colon in that line. Fixed an the issue has gone away.

Resources