{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import qrcode\n", "from PIL import Image" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "img_bg = Image.open('data/src/lena.jpg')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qr = qrcode.QRCode(box_size=2)\n", "qr.add_data('I am Lena')\n", "qr.make()\n", "img_qr = qr.make_image()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "pos = (img_bg.size[0] - img_qr.size[0], img_bg.size[1] - img_qr.size[1])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "img_bg.paste(img_qr, pos)\n", "img_bg.save('data/dst/qr_lena.png')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "face = Image.open('data/src/lena.jpg').crop((175, 90, 235, 150))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qr_big = qrcode.QRCode(\n", " error_correction=qrcode.constants.ERROR_CORRECT_H\n", ")\n", "qr_big.add_data('I am Lena')\n", "qr_big.make()\n", "img_qr_big = qr_big.make_image().convert('RGB')" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "pos = ((img_qr_big.size[0] - face.size[0]) // 2, (img_qr_big.size[1] - face.size[1]) // 2)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "img_qr_big.paste(face, pos)\n", "img_qr_big.save('data/dst/qr_lena2.png')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }