diff --git a/Image2DB.py b/Image2DB.py new file mode 100644 index 0000000..53bbfbb --- /dev/null +++ b/Image2DB.py @@ -0,0 +1,54 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import random +from PIL import Image, ImageDraw #Подключим необходимые библиотеки. +from PIL.ImageQt import ImageQt + +import sqlite3 as lite +import sys +from PyQt5.QtWidgets import (QWidget, QHBoxLayout, + QLabel, QApplication) +from PyQt5.QtGui import QPixmap, QImage, qRgb + + +class Example(QWidget): + + def __init__(self): + super().__init__() + + self.initUI() + + + def initUI(self): + + con = lite.connect('image.db') + cur = con.cursor() + + file = open("big.jpg", "rb") + + img = file.read() + + print(img) + + file.close() + + binary = lite.Binary(img) + + cur.execute("INSERT INTO Images(Data) VALUES (?)", (binary,)) + + con.commit() + con.close() + + + + self.move(300, 200) + self.setWindowTitle('Example') + self.show() + + +if __name__ == '__main__': + + app = QApplication(sys.argv) + ex = Example() + sys.exit(app.exec_()) \ No newline at end of file diff --git a/ImageCrop.py b/ImageCrop.py new file mode 100644 index 0000000..f1fc094 --- /dev/null +++ b/ImageCrop.py @@ -0,0 +1,57 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import random +from PIL import Image, ImageDraw # Подключим необходимые библиотеки. +from PIL.ImageQt import ImageQt + +import sys +from PyQt5.QtWidgets import (QWidget, QHBoxLayout, + QLabel, QApplication) +from PyQt5.QtGui import QPixmap, QImage, qRgb + + +class Example(QWidget): + + def __init__(self): + super().__init__() + + self.initUI() + + def initUI(self): + imageFile = "dark_elf.jpg" + + image = Image.open(imageFile) + + print(image.size) + cx, cy = image.size[0]/2, image.size[1]/2 + d = 50 + + #image = image.crop((cx-d, cy-d, cx+d, cy+d)) + + image = image.crop((50, 50, 150, 150)) # 50, 50 - x,y start coordinate; 150, 150 - final size + + draw = ImageDraw.Draw(image) + + + + img_tmp = ImageQt(image.convert('RGBA')) + + hbox = QHBoxLayout(self) + pixmap = QPixmap.fromImage(img_tmp) + + lbl = QLabel(self) + lbl.setPixmap(pixmap) + + hbox.addWidget(lbl) + self.setLayout(hbox) + + self.move(300, 200) + self.setWindowTitle('Example') + self.show() + + +if __name__ == '__main__': + app = QApplication(sys.argv) + ex = Example() + sys.exit(app.exec_()) diff --git a/big.jpg b/big.jpg new file mode 100644 index 0000000..615cd91 Binary files /dev/null and b/big.jpg differ diff --git a/ikruglov_hw_020.py b/ikruglov_hw_020.py new file mode 100644 index 0000000..b8e6aaa --- /dev/null +++ b/ikruglov_hw_020.py @@ -0,0 +1,61 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import random +from PIL import Image, ImageDraw #Подключим необходимые библиотеки. +from PIL.ImageQt import ImageQt + +import sys +from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QLabel, QApplication) +from PyQt5.QtGui import QPixmap, QImage, qRgb + + +class Example(QWidget): + + def __init__(self): + super().__init__() + + self.initUI() + + + def initUI(self): + + imageFile = "big.jpg" + # imageFile = "small.png" + + image = Image.open(imageFile) + + # выравнивание по ширине (image.size[0]) + width = 800 + # высоту нужно определить (image.size[1]) + height = int(width * image.size[1] / image.size[0]) + + # указываем конечные размеры (без сохранения соотношения) + # width = 800 + # height = 800 + + image = image.resize((width, height), Image.ANTIALIAS) + + draw = ImageDraw.Draw(image) + + img_tmp = ImageQt(image.convert('RGBA')) + + hbox = QHBoxLayout(self) + pixmap = QPixmap.fromImage(img_tmp) + + lbl = QLabel(self) + lbl.setPixmap(pixmap) + + hbox.addWidget(lbl) + self.setLayout(hbox) + + self.move(300, 200) + self.setWindowTitle('Example') + self.show() + + +if __name__ == '__main__': + + app = QApplication(sys.argv) + ex = Example() + sys.exit(app.exec_()) \ No newline at end of file diff --git a/image.db b/image.db new file mode 100644 index 0000000..2ae7fa7 Binary files /dev/null and b/image.db differ