Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Image2DB.py
Original file line number Diff line number Diff line change
@@ -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_())
57 changes: 57 additions & 0 deletions ImageCrop.py
Original file line number Diff line number Diff line change
@@ -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_())
Binary file added big.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
61 changes: 61 additions & 0 deletions ikruglov_hw_020.py
Original file line number Diff line number Diff line change
@@ -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_())
Binary file added image.db
Binary file not shown.