Image Restoration code in jpg format implemented by python

Source: Internet
Author: User

Image Restoration code in jpg format implemented by python

This article mainly introduces the jpg Format Image repair Code implemented by python. This article provides the implementation code directly. If you need it, refer

Recently, the damaged jpg file is fixed for the customer, and the effect is acceptable, but it is not guaranteed to be applicable in any situation.

If you have damaged the photo, try it. If you can use it, leave a message for me.

The Code is as follows:

#-*-Coding: utf8 -*-

#! /Usr/bin/env python

_ Author _ = 'fengxing'

_ Date _ = '2017-1-18'

Import sys

Def jpgfix (name ):

Sig = '\ xFF \ xD8 \ xFF \ xdb'

With open (name, "r") as fd:

Fd. seek (len (sig), 0)

Jpg = fd. read ()

Pos = jpg. find (sig)

If pos <0:

Raise Exception ('not find signature ')

Jpg = jpg [pos:]

With open (name, "w") as fd:

Fd. seek (0, 0)

Print 'size is: ', len (jpg)

Fd. write (jpg)

If _ name _ = '_ main __':

Try:

While True:

Jpgfix (sys. argv [1])

Except t:

Print 'done'

The usage method is simple. Save the above Code as jpg_fix.py, and then enter

The Code is as follows:

Python jpg_fix.py ABC.jpg

ABC.jpg is the image you want to repair (Note: Back up the image before restoration)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.