Example #1
0
    def test_sanity(self):
        for mode in ('RGB', 'RGBA', 'L', 'P', '1'):
            src = hopper(mode)
            data = ImageQt.toqimage(src)

            self.assertIsInstance(data, QImage)
            self.assertFalse(data.isNull())

            # reload directly from the qimage
            rt = ImageQt.fromqimage(data)
            if mode in ('L', 'P', '1'):
                self.assert_image_equal(rt, src.convert('RGB'))
            else:
                self.assert_image_equal(rt, src)

            if mode == '1':
                # BW appears to not save correctly on QT4 and QT5
                # kicks out errors on console:
                #     libpng warning: Invalid color type/bit depth combination
                #                     in IHDR
                #     libpng error: Invalid IHDR data
                continue

            # Test saving the file
            tempfile = self.tempfile('temp_{}.png'.format(mode))
            data.save(tempfile)

            # Check that it actually worked.
            reloaded = Image.open(tempfile)
            # Gray images appear to come back in palette mode.
            # They're roughly equivalent
            if QT_VERSION == 4 and mode == 'L':
                src = src.convert('P')
            self.assert_image_equal(reloaded, src)
Example #2
0
    def updateThumb(self, thumbId : int, path : str, pic : Image.Image):
        thumb = ImageQt.toqimage(pic)
        thumb = self.resizeImage(thumb, (self.thumbWidth, self.thumbHeight))
        thumb = QPixmap.fromImage(thumb)

        self.thumbs[path] = thumb
        self.repaintCanvas()
Example #3
0
    def test_sanity(self):
        for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
            data = ImageQt.toqpixmap(hopper(mode))

            self.assertIsInstance(data, QPixmap)
            self.assertFalse(data.isNull())

            # Test saving the file
            tempfile = self.tempfile('temp_{}.png'.format(mode))
            data.save(tempfile)
    def roundtrip(self, expected):
        # PIL -> Qt
        intermediate = expected.toqimage()
        # Qt -> PIL
        result = ImageQt.fromqimage(intermediate)

        if intermediate.hasAlphaChannel():
            self.assert_image_equal(result, expected.convert('RGBA'))
        else:
            self.assert_image_equal(result, expected.convert('RGB'))
Example #5
0
    def load_pixmap(self, path, bb=None):
        im = Image.open(str(path)).convert('RGBA')

        if bb is not None:
            overlay = Image.new('L', im.size, color=255/2)
            overlaydraw = ImageDraw.Draw(overlay)
            overlaydraw.rectangle(bb, fill=0)
            black = Image.new('RGBA', im.size, color=0xFF000000)
            black.putalpha(overlay)
            im = Image.alpha_composite(im, black)
        return ImageQt.toqpixmap(im)
Example #6
0
    def test_sanity(self):
        PillowQtTestCase.setUp(self)
        for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
            data = ImageQt.toqimage(hopper(mode))

            self.assertIsInstance(data, QImage)
            self.assertFalse(data.isNull())

            # Test saving the file
            tempfile = self.tempfile('temp_{0}.png'.format(mode))
            data.save(tempfile)
Example #7
0
    def test_sanity(self):
        PillowQtTestCase.setUp(self)

        for mode in ("1", "RGB", "RGBA", "L", "P"):
            data = ImageQt.toqpixmap(hopper(mode))

            self.assertTrue(isinstance(data, QPixmap))
            self.assertFalse(data.isNull())

            # Test saving the file
            tempfile = self.tempfile("temp_{0}.png".format(mode))
            data.save(tempfile)
Example #8
0
    def load(self):
        self.leftList.clear()
        self.rightList.clear()
        self.topList.clear()
        self.bottomList.clear()
        self._history = []
        self.img_index = 0
        self.obj_index = 0

        image_lists = [[]] * 4
        for i in range(4):
            with self._outfile(i).open('r') as fp:
                image_lists[i] = [line.strip().rsplit(' ', 1) for line in fp.readlines()]

        for i, image in enumerate(self.pascalClass.images):
            for j, bb in enumerate(self.pascalClass.bounding_boxes[image.stem]):
                empty = True
                for k in range(4):
                    if len(image_lists[k]) > 0:
                        empty = False
                        if image_lists[k][0][0] == image.stem and image_lists[k][0][1] == str(j):
                            image_lists[k].pop(0)
                            im = Image.open(str(image)).convert('RGBA')
                            overlay = Image.new('L', im.size, color=255/2)
                            overlaydraw = ImageDraw.Draw(overlay)
                            overlaydraw.rectangle(bb, fill=0)
                            black = Image.new('RGBA', im.size, color=0xFF000000)
                            black.putalpha(overlay)
                            im = Image.alpha_composite(im, black)
                            pixmap = ImageQt.toqpixmap(im)

                            self._history.append((k, self.lists[k], self.lists[k].addImage(pixmap, image)))
                            break
                if empty:
                    break
            if empty:
                break
        self.img_index = i
        self.obj_index = j
        self.next()
Example #9
0
    def update_manga_list(self):
        cursor = Library.db.cursor()
        query = "SELECT title, cover_url FROM manga ORDER BY title"
        cursor.execute(query)
        data_query = cursor.fetchall()
        self.manga_list.clear()

        for data in data_query:
            title = data[0]
            cover_file = os.path.join(Library.directory, ".Cover", title + ".jpg")
            if not os.path.isfile(cover_file):
                continue
            # Needs to be a copy as it will resize the actual image in the library dict
            image = Library.covers[title].copy()
            image = image.resize((self.icon_size.width(), self.icon_size.height()), Image.ANTIALIAS)
            pix_map = ImageQt.toqpixmap(image)
            icon = QtGui.QIcon(pix_map)
            item = QtGui.QListWidgetItem(title, self.manga_list)
            item.setStatusTip(title)
            item.setIcon(icon)
            item.setSizeHint(self.icon_size + self.icon_padding)
            item.setBackgroundColor(QtGui.QColor("#F9F9F9"))
Example #10
0
 def showImage(self, image):
     '''convert it into pillow image '''
     img = Image.fromarray(image)
     qt_img = ImageQt.ImageQt(img)
     self.imageCanvas.setPixmap(QtGui.QPixmap.fromImage(qt_img))
Example #11
0
 def save_file(self):
     path, _ = QFileDialog.getSaveFileName(self, 'Save file', 'new_image.jpg', "Image file (*.jpg)")
     result_pic = ImageQt.fromqpixmap(self.img_label.pixmap)
     result_pic.save(path)
Example #12
0
def test_image():
    for mode in ("1", "RGB", "RGBA", "L", "P"):
        ImageQt.ImageQt(hopper(mode))
Example #13
0
def test_closed_file():
    with warnings.catch_warnings():
        ImageQt.ImageQt("Tests/images/hopper.gif")
Example #14
0
    def updateCountdown(self, event):

        picture = Image.open(event.picture)
        self._gui.centralWidget().picture = ImageQt.ImageQt(picture)
        self._gui.centralWidget().update()
Example #15
0
 def checkrgb(r, g, b):
     val = ImageQt.rgb(r, g, b)
     val = val % 2**24  # drop the alpha
     self.assertEqual(val >> 16, r)
     self.assertEqual(((val >> 8) % 2**8), g)
     self.assertEqual(val % 2**8, b)
 def set_image_2(self, pil_img):
     self.imageField2.setPixmap(
         QtGui.QPixmap.fromImage(ImageQt.ImageQt(pil_img)))
     self.imageField2.adjustSize()
Example #17
0
from PyQt4.QtGui import *
from PIL import Image, ImageTk, ImageQt
from PyQt4 import QtCore, QtGui
from roverController_02 import Ui_MainWindow
import time
from PIL import Image, ImageDraw, ImageFont

im = Image.open('map_a_building1.png')
nn = Image.open('None.jpg')
rover_X0 = Image.open('rover_X.png')
rover_Y0 = Image.open('rover_Y.png')

X_angle = 7
Y_angle = -3

image = ImageQt.ImageQt(im)

image_Map = im


class MyForm(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # self.ui.checkBox_motor.stateChanged.connect(self.checBoxMotor)
        self.ui.pushButton_m1f.clicked.connect(self.button_m1f)
        self.ui.M1.valueChanged.connect(self.M1)

        self.ui.textBrowser.setFontPointSize(11)
Example #18
0
 def savePhoto(self):
     global fsplit
     image = ImageQt.fromqpixmap(self.ui.label.pixmap())
     image.save('./outputs/Snap/'+fsplit+'.png')
Example #19
0
 def set_map_pil(self, img):
     self.pixel_map = QtGui.QPixmap.fromImage(ImageQt.ImageQt(img))
     self.update()
Example #20
0
    def refresh_new_layer(self):

        img_qt = ImageQt(self.new_layer_image)
        pix_map = QPixmap.fromImage(img_qt)
        self.new_layer_piece.setPixmap(pix_map)
Example #21
0
    S6 = ['R05R_S6', 'S_S6'],
    S7 = ['R05R_S7', 'S_S7'],
    S8 = ['R05R_S8', 'S_S8'],
    S9 = ['R05R_S9', 'S_S9'],
    S10 = ['R05R_S10', 'S_S10'],

    R1 = ['R_R1', 'S_S1'],
    R2 = ['R_R2', 'S_S2'],
    R3 = ['R_R3', 'S_S3'],
    R4 = ['R_R4', 'S_S4'],

)

app = QtGui.QApplication(sys.argv, False)
im = Image.open("RCTP.png")
qt_im = ImageQt.ImageQt(im)

def portionCLSD(start=None, end=None, baystart=None, bayend=None, linestyle="solid", note=""):
    if baystart != None:
        print "% " + baystart,
        x, y = points["b"+baystart]
        blk = (x - 20, y, x + 20, y)
        print blk
        drawLine(blk, fill="red", width=8, style=linestyle)
        drawLabel(points["b"+baystart], points["b"+baystart], note)

        if bayend != None:
            print "% " + bayend,
            x, y = points["b" + bayend]
            blk = (x - 20, y, x + 20, y)
            print blk
Example #22
0
 def __init__(self, image):
     super().__init__()
     self.image = ImageQt.ImageQt(Image.open(image))
     self.origin_pixmap = QtGui.QPixmap.fromImage(self.image)
     self.paint()
Example #23
0
 def update_pixmap(self):
     self.image_qt = ImageQt.ImageQt(self.image)
     self.pixmap = QtGui.QPixmap(self.image_qt)
     self.lbl_image.setPixmap(
         self.pixmap.scaled(self.lbl_image.size(), QtCore.Qt.KeepAspectRatio
                            ))  # , QtCore.Qt.SmoothTransformation))
Example #24
0
 def preview(self, image):
     self.image = image
     pixmap = ImageQt.toqpixmap(self.image)
     self.guider_preview_label.setPixmap(pixmap)
    def np2qpixmap(self, np_img):
        """convert np array into pixmap"""
        im8 = Image.fromarray(np_img)
        imQt = QtGui.QImage(ImageQt.ImageQt(im8))

        return QtGui.QPixmap.fromImage(imQt)
Example #26
0
 def setImage(self, image):
     self.bind_image = ImageQt.ImageQt(image)
     self.setPixmap(QtGui.QPixmap.fromImage(self.bind_image))
Example #27
0
 def saveEvent(self):
     image = ImageQt.fromqpixmap(self.ui.label_image_output.pixmap())
     image.save('test.png')
Example #28
0
    def _showPreview(self, state):

        self._gui.centralWidget().picture = ImageQt.ImageQt(state.picture)
        self._gui.centralWidget().update()
Example #29
0
    def update_info_panel(self):
        cursor = Library.db.cursor()

        # Getting the selected item
        item = self.manga_list.currentItem()
        title = item.text()
        cover = Library.covers[title]
        # cover.thumbnail((235, 350), Image.ANTIALIAS)
        pix_map = ImageQt.toqpixmap(cover)
        pix_map = pix_map.scaledToHeight(350, QtCore.Qt.SmoothTransformation)
        self.cover_label.setPixmap(pix_map)
        self.cover_label.resize(pix_map.size())

        query = (
            "SELECT title, authors, year, genre, publish_status, "
            "scan_status, description FROM manga WHERE title='{}'".format(title)
        )
        cursor.execute(query)
        data = cursor.fetchone()

        if data is None:
            self.show_clean_info_panel()
            return

        # Breaking up the genre string so that it is not so big
        genre_string = data[3].split(",")
        genre = ""
        character_count = 0
        for g in genre_string:
            word_count = len(g)
            if character_count + word_count >= 24:
                genre += "\n{}".format(g)
                character_count = word_count
            else:
                if len(genre) == 0:
                    genre = g
                else:
                    genre += ", {}".format(g)
                character_count += word_count

        author_string = data[1].split(",")
        author = ""
        character_count = 0
        for a in author_string:
            word_count = len(a)
            if character_count + word_count >= 24:
                author += "\n{}".format(a)
                character_count = word_count
            else:
                if len(author) == 0:
                    author = a
                else:
                    author += ", {}".format(a)
                character_count += word_count

        title = ""
        character_count = 0
        for word in data[0].split(" "):
            word_count = len(word)
            if character_count + word_count >= 25:
                title += "\n{}".format(word)
                character_count = word_count
            else:
                if len(title) == 0:
                    title = word
                else:
                    title += " {}".format(word)
                    character_count += word_count

        # Setting all of the label to display the information
        self.label_title.setText(title)
        # self.label_title.setText(data[0])
        self.label_author.setText(author)
        self.label_year.setText(str(data[2]))
        self.label_genre.setText(genre)
        self.label_publish.setText(data[4])
        self.label_scan.setText(data[5])
        self.description_box.setText(data[6])
        self.status_message(title)
Example #30
0
 def checkrgb(r, g, b):
     val = ImageQt.rgb(r, g, b)
     val = val % 2**24  # drop the alpha
     self.assertEqual(val >> 16, r)
     self.assertEqual(((val >> 8) % 2**8), g)
     self.assertEqual(val % 2**8, b)
Example #31
0
 def test_image(self):
     for mode in ('1', 'RGB', 'RGBA', 'L', 'P'):
         ImageQt.ImageQt(hopper(mode))
 def roundtrip(self, expected):
     result = ImageQt.fromqimage(expected.toqimage())
     # Qt saves all images as rgb
     self.assert_image_equal(result, expected.convert('RGB'))
Example #33
0
 def checkrgb(r, g, b):
     val = ImageQt.rgb(r, g, b)
     val = val % 2**24  # drop the alpha
     assert val >> 16 == r
     assert ((val >> 8) % 2**8) == g
     assert val % 2**8 == b
Example #34
0
    def getQImage(self, pixmap):
        mode = "RGBA" if pixmap.alpha else "RGB"

        img = Image.frombytes(mode, [pixmap.width, pixmap.height],
                              pixmap.samples)
        return ImageQt.ImageQt(img)
Example #35
0
 def prep_update(self):
     img = Image.fromarray(np.uint8(self.result))
     self.temp = ImageQt.ImageQt(img)
     self.update.emit(QtGui.QPixmap.fromImage(self.temp))
Example #36
0
def adjust_image_light(qimage, factor):
    image = ImageQt.fromqimage(qimage)
    res_qimg = ImageQt.ImageQt(add_light(image, factor))
    return res_qimg
Example #37
0
 def loadTGA(tga: bytes) -> QtGui.QPixmap:
     """Load a TGA image as a QPixmap. For some reason, some images accepted by Freelancer do not load in PyQt - but
     they do with the help of Pillow."""
     image = ImageQt.ImageQt(Image.open(BytesIO(tga)))
     return QtGui.QPixmap.fromImage(image)
Example #38
0
 def set_barcodes(self, code):
     img = Code128().get_image(code)
     barcode_image = ImageQt.ImageQt(img.convert('RGBA'))
     barcode_pix = QtGui.QPixmap.fromImage(barcode_image).scaled(200, 50, 1, 1)
     self.barcode.setPixmap(barcode_pix)
     self.barcode_b.setPixmap(barcode_pix)
 def roundtrip(self, expected):
     result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected))
     # Qt saves all pixmaps as rgb
     self.assert_image_equal(result, expected.convert("RGB"))
Example #40
0
 def draw_img(self, img: Image, img_box: QLabel):
     self.pixmap_original = ImageQt.toqpixmap(img)
     img_box.setPixmap(self.pixmap_original)
Example #41
0
    def place_preview_img(self):
        img = _get_img_with_all_operations()

        preview_pix = ImageQt.toqpixmap(img)
        self.viewer.setPhoto(preview_pix)
Example #42
0
 def display_original_image(self):
     self.qimage_resized_original = ImageQt.ImageQt(
         self.resized_original_image)
     self.displayed_image = QtGui.QPixmap.fromImage(
         self.qimage_resized_original)
     self.label_img.setPixmap(self.displayed_image)
 def roundtrip(self, expected):
     PillowQtTestCase.setUp(self)
     result = ImageQt.fromqpixmap(ImageQt.toqpixmap(expected))
     # Qt saves all pixmaps as rgb
     self.assert_image_equal(result, expected.convert('RGB'))
Example #44
0
 def checkrgb(r,g,b):
     val = ImageQt.rgb(r,g,b)
     val = val % 2**24 # drop the alpha
     assert_equal(val >> 16, r)
     assert_equal(((val >> 8 ) % 2**8), g)
     assert_equal(val % 2**8, b)