Esempio n. 1
0
    def test_generate_crc_diagram_from_python_project(self):
        with self.runner.isolated_filesystem():
            result = self.runner.invoke(main, [self.source_project, 'out.png'])

            self.assertEqual(result.exit_code, 0)
            with open('out.png', 'rb') as out:
                self.assertEqual(imghdr.test_png(out.read(), None), 'png')
Esempio n. 2
0
def _what_file(bytes):
    if imghdr.test_bmp(bytes, 0) == "bmp":
        return "bmp"
    elif imghdr.test_gif(bytes, 0) == "gif":
        return "gif"
    elif imghdr.test_jpeg(bytes, 0) == "jpeg":
        return "jpeg"
    elif imghdr.test_webp(bytes, 0) == "webp":
        return "webp"
    elif imghdr.test_png(bytes, 0) == 'png':
        return 'png'
    def test_camera_image(self):

        camera = self.instance_manager.config_manager.load_camera(
            self.simulation_camera)

        # Retrieve a single image from the camera.
        camera.connect()
        image_raw_bytes = camera.get_image()
        camera.disconnect()

        image = get_png_from_image(image_raw_bytes)

        self.assertEqual("png", imghdr.test_png(image, None),
                         "Image is not a valid PNG.")

        camera_size = camera.get_geometry()
        png_size = Image.open(BytesIO(image)).size

        self.assertEqual(camera_size, png_size,
                         "Camera and image size are not the same.")
Esempio n. 4
0
def ConvertDatToImage(srcDatFile, destDir):
    readStream = open(srcDatFile, 'rb')
    readBuf = readStream.read()
    buf6 = readBuf[0:4]
    hFEFE, nPicCount = struct.unpack("<HH", buf6)
    
    for iPic in range(0, nPicCount):
        buf9 = readBuf[4+9*iPic: 4+9*iPic+9]
        bPicInfo, iOffset, iSize = struct.unpack("<bii", buf9)
        
        bufIPic = readBuf[iOffset: iOffset+iSize]    
        strExt = ""
        if(imghdr.test_png(bufIPic, None)):
            strExt = ".png"
        elif(imghdr.test_jpeg(bufIPic, None)):
            strExt = ".jpg"
        
        newJpgName = '''%s_%d%s''' % (os.path.splitext(os.path.split(srcDatFile)[1])[0], iPic, strExt)
        destFile = os.path.join(destDir, newJpgName) 
        outFS = open(destFile, 'wb')
        outFS.write(bufIPic)
        outFS.close()
Esempio n. 5
0
	async def add_(self, name, url, author_id):
		try:
			await self.get(name)
		except EmoteNotFoundError:
			image_data = await self.fetch(url)
			if imghdr.test_gif(image_data, None) == 'gif':
				animated = True
			elif imghdr.test_png(image_data, None) == 'png' or imghdr.test_jpeg(image_data, None) == 'jpeg':
				animated = False
			else:
				raise InvalidImageError

			guild = self.free_guild(animated)
			emote = await guild.create_custom_emoji(name=name, image=image_data)
			await self.bot.db.execute(
				'INSERT INTO emojis(name, id, author, animated) VALUES($1, $2, $3, $4)',
				name,
				emote.id,
				author_id,
				animated)
			return 'Emote %s successfully created.' % emote
		else:
			raise EmoteExistsError
Esempio n. 6
0
def data_is_acceptable_img(data: str) -> bool:
    """Check if a given file data is a PNG or JPEG."""
    return imghdr.test_png(data, None) or imghdr.test_jpeg(data, None)
Esempio n. 7
0
            if glob.redis.get("lets:screenshot:{}".format(userID)) is not None:
                return self.write("no")
            glob.redis.set("lets:screenshot:{}".format(userID), 1, 60)

            while os.path.exists(
                    path := BASE_PATH.format(generalUtils.randomString(8))):
                pass

            # Check if the filesize is not ridiculous. Through my checking I
            # have discovered all screenshots on rosu are below 500kb.
            if sys.getsizeof(self.request.files["ss"][0]["body"]) > 500000:
                return self.write("filesize")

            # Check if the file contents are actually fine (stop them uploading eg videos).
            if (not test_jpeg(self.request.files["ss"][0]["body"], 0))\
            and (not test_png(self.request.files["ss"][0]["body"], 0)):
                return self.write("unknownfiletype")

            # Write screenshot file to screenshots folder
            with open(path, "wb") as f:
                f.write(self.request.files["ss"][0]["body"])

            # Output
            log.info("New screenshot ({})".format(path))

            # Dirty method.
            ss_ting = path.removeprefix(
                glob.conf.config["server"]["screenshotspath"])
            # Return screenshot link
            self.write("{}/ss{}".format(
                glob.conf.config["server"]["serverurl"], ss_ting))
Esempio n. 8
0
 def update_event(self, inp=-1):
     self.set_output_val(0, imghdr.test_png(self.input(0), self.input(1)))