本文将介绍Python:从图像中删除Exif信息的详细情况,特别是关于python删除指定元素的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于and
本文将介绍Python:从图像中删除Exif信息的详细情况,特别是关于python删除指定元素的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于android – 从图像中删除或更新exif缩略图、javascript – 从图像中剥离EXIF数据、Java从图片中读取图片的元数据Exif信息、python利用PIL库读取图片的EXIF信息的知识。
本文目录一览:- Python:从图像中删除Exif信息(python删除指定元素)
- android – 从图像中删除或更新exif缩略图
- javascript – 从图像中剥离EXIF数据
- Java从图片中读取图片的元数据Exif信息
- python利用PIL库读取图片的EXIF信息
Python:从图像中删除Exif信息(python删除指定元素)
为了减小要在网站中使用的图像的大小,我将质量降低到80-85%。这样可以最大程度地减小图像尺寸。
为了进一步减小尺寸而不影响质量,我的朋友指出,相机的原始图像包含大量称为Exif
info的元数据。由于无需为网站中的图像保留此Exif信息,因此我们可以将其删除。这将使尺寸进一步减小3-10 kB。
但是我无法在Python代码中找到合适的库来执行此操作。我已经浏览了相关问题并尝试了一些方法:
原始图片:http://mdb.ibcdn.com/8snmhp4sjd75vdr27gbadolc003i.jpg
- 滋润
/usr/local/bin/mogrify -strip filename
结果:http
:
//s23.postimg.org/aeaw5x7ez/8snmhp4sjd75vdr27gbadolc003i_mogrify.jpg
此方法将尺寸从105 kB减小到99.6 kB,但还改变了颜色质量。
- Exif工具
exiftool -all= filename
结果:http
:
//s22.postimg.org/aiq99o775/8snmhp4sjd75vdr27gbadolc003i_exiftool.jpg
此方法将大小从105 kB减小到72.7 kB,但还改变了颜色质量。
- 该答案详细说明了如何操作Exif信息,但是如何使用它来删除该信息?
任何人都可以在不更改图像的颜色,尺寸和其他属性的情况下帮助我删除所有多余的元数据吗?
答案1
小编典典您可以尝试使用Python Image
Lirbary(PIL)加载图像,然后再次将其保存到其他文件。那应该删除元数据。
android – 从图像中删除或更新exif缩略图
我在我的应用程序中裁剪图像并使用sanselan库复制所有exif数据无损.然后,我相应地更新宽度/高度/旋转.
我找不到任何方法来更新exif缩略图或删除它,任何想法如何做到这一点?
解决方法
private void removeThumbnails(ContentResolver contentResolver,long photoId) { try { Cursor thumbnails = contentResolver.query( MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,null,MediaStore.Images.Thumbnails.IMAGE_ID + "=?",new String[]{String.valueOf(photoId)},null); if (thumbnails != null) { for (thumbnails.movetoFirst(); !thumbnails.isAfterLast() && !thumbnails.isBeforeFirst(); thumbnails.movetoNext()) { long thumbnailId = thumbnails.getLong(thumbnails.getColumnIndex(MediaStore.Images.Thumbnails._ID)); String path = thumbnails.getString(thumbnails.getColumnIndex(MediaStore.Images.Thumbnails.DATA)); File file = new File(path); if (file.delete()) { contentResolver.delete(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,MediaStore.Images.Thumbnails._ID + "=?",new String[]{String.valueOf(thumbnailId)}); } } thumbnails.close(); } } catch (Exception e) { } }
所以我先删除了它的缩略图,然后对图像进行了操作
因此,你可以尝试删除缩略图,然后尝试裁剪它
javascript – 从图像中剥离EXIF数据
EXIF.getData(oimg,function() { var orientation = EXIF.getTag(this,"Orientation"); });
但是,我没有找到任何方法来实际删除Exif数据,只能检索它.
更具体地说,我正在努力去摆脱在某些浏览器上旋转图像的Exif数据.
解决方法
> read the file进 arraybuffer
> find所需数据和 remove it
>从剩余的数据创建一个 blob
> upload它与 ajax
这是一个小的演示,选择一个图像与方向数据,看看它的外观与它(仅现代浏览器).
http://jsfiddle.net/mowglisanu/frhwm2xe/3/
<input id="erd" type="file"/>
var input = document.querySelector('#erd'); input.addEventListener('change',load); function load(){ var fr = new FileReader(); fr.onload = process; fr.readAsArrayBuffer(this.files[0]); window.open(URL.createObjectURL(this.files[0]),"_blank","toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400"); } function process(){ var dv = new DataView(this.result); var offset = 0,recess = 0; var pieces = []; var i = 0; if (dv.getUint16(offset) == 0xffd8){ offset += 2; var app1 = dv.getUint16(offset); offset += 2; while (offset < dv.byteLength){ console.log(offset,'0x'+app1.toString(16),recess); if (app1 == 0xffe1){ pieces[i] = {recess:recess,offset:offset-2}; recess = offset + dv.getUint16(offset); i++; } else if (app1 == 0xffda){ break; } offset += dv.getUint16(offset); var app1 = dv.getUint16(offset); offset += 2; } if (pieces.length > 0){ var newPieces = []; pieces.forEach(function(v){ newPieces.push(this.result.slice(v.recess,v.offset)); },this); newPieces.push(this.result.slice(recess)); var br = new Blob(newPieces,{type: 'image/jpeg'}); window.open(URL.createObjectURL(br),height=400"); } } }
Java从图片中读取图片的元数据Exif信息
下面是小编 jb51.cc 通过网络收集整理的代码片段。
小编小编现在分享给大家,也给大家做个参考。
import java.io.File; import java.io.IOException; import com.drew.imaging.ImageMetadataReader; import com.drew.imaging.ImageProcessingException; public class SampleUsage { /** * 图片信息获取Metadata元数据信息 * @param fileName 需要解析的文件 * @return */ public ImgInfoBean parseImgInfo (String fileName) { File file = new File(fileName); ImgInfoBean imgInfoBean = null; try { Metadata Metadata = ImageMetadataReader.readMetadata(file); imgInfoBean = printimageTags(file,Metadata); } catch (ImageProcessingException e) { System.err.println("error 1a: " + e); } catch (IOException e) { System.err.println("error 1b: " + e); } return imgInfoBean; } /** * 读取Metadata里面的信息 * @param sourceFile 源文件 * @param Metadata Metadata元数据信息 * @return */ private ImgInfoBean printimageTags(File sourceFile,Metadata Metadata) { ImgInfoBean imgInfoBean = new ImgInfoBean (); imgInfoBean.setImgSize(sourceFile.getTotalSpace()); imgInfoBean.setImgName(sourceFile.getName()); for (Directory directory : Metadata.getDirectories()) { for (Tag tag : directory.getTags()) { String tagName = tag.getTagName(); String desc = tag.getDescription(); if (tagName.equals("Image Height")) { //图片高度 imgInfoBean.setImgHeight(desc); } else if (tagName.equals("Image Width")) { //图片宽度 imgInfoBean.setImgWidth(desc); } else if (tagName.equals("Date/Time Original")) { //拍摄时间 imgInfoBean.setDateTime(desc); } else if (tagName.equals("GPS Altitude")) { //海拔 imgInfoBean.setAltitude(desc); } else if (tagName.equals("GPS Latitude")) { //纬度 imgInfoBean.setLatitude(pointToLatlong(desc)); } else if (tagName.equals("GPS Longitude")) { //经度 imgInfoBean.setLongitude(pointToLatlong(desc)); } } for (String error : directory.getErrors()){ System.err.println("ERROR: " + error); } } return imgInfoBean; } /** * 经纬度转换 度分秒转换 * @param point 坐标点 * @return */ public String pointToLatlong (String point ) { Double du = Double.parseDouble(point.substring(0,point.indexOf("°")).trim()); Double fen = Double.parseDouble(point.substring(point.indexOf("°")+1,point.indexOf("'")).trim()); Double miao = Double.parseDouble(point.substring(point.indexOf("'")+1,point.indexOf("\"")).trim()); Double duStr = du + fen / 60 + miao / 60 / 60 ; return duStr.toString(); } public static void main(String[] args) { ImgInfoBean imgInfoBean = new SampleUsage().parseImgInfo("C:\\DSC_4564.JPG"); System.out.println(imgInfoBean.toString()); } }
文件信息bean类。
public class ImgInfoBean { private String imgHeight ;//图片高度 private String imgWidth ;//图片宽度 private String dateTime ;//拍摄时间 private String altitude ;//海拔 private String latitude;//纬度 private String longitude ;//经度 private Long imgSize; //文件大小 private String imgName; //文件名称 public Long getImgSize() { return imgSize; } public void setImgSize(Long imgSize) { this.imgSize = imgSize; } public String getImgName() { return imgName; } public void setImgName(String imgName) { this.imgName = imgName; } public String getImgHeight() { return imgHeight; } public void setImgHeight(String imgHeight) { this.imgHeight = imgHeight; } public String getImgWidth() { return imgWidth; } public void setImgWidth(String imgWidth) { this.imgWidth = imgWidth; } public String getDateTime() { return dateTime; } public void setDateTime(String dateTime) { this.dateTime = dateTime; } public String getAltitude() { return altitude; } public void setAltitude(String altitude) { this.altitude = altitude; } public String getLatitude() { return latitude; } public void setLatitude(String latitude) { this.latitude = latitude; } public String getLongitude() { return longitude; } public void setLongitude(String longitude) { this.longitude = longitude; } public String toString (){ return "[图片信息]文件名称:"+ this.imgName+" 文件大小:"+this.imgSize +" 高度:"+this.imgHeight+" 宽度:"+this.imgWidth+" 拍摄时间:"+this.dateTime+" 海拔:"+this.altitude+" 纬度:"+this.latitude+" 经度:"+this.longitude; } }
以上是小编(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给程序员好友。
python利用PIL库读取图片的EXIF信息
下面是小编 jb51.cc 通过网络收集整理的代码片段。
小编小编现在分享给大家,也给大家做个参考。
# -*- coding: Windows-1251 -*- ''' rename_to_exiftime.py Rename JPEG files according to EXIF-date using PIL If global variable CREATE_HARDLINK is set,script creates Windows (XP) batch file for creating hardlink version of source files Author: Denis Barmenkov <[email protected]> Modified by: Jorge Barnaby <[email protected]> Improved rename process on duplicates copyright: this code is free,but if you want to use it,please keep this multiline comment along with function source. Thank you. 2009-02-10 18:14 ''' import Image import os import re import sys import time CREATE_HARDLINK=0 def extract_jpeg_exif_time(jpegfn): if not os.path.isfile(jpegfn): return None try: im = Image.open(jpegfn) if hasattr(im,'_getexif'): exifdata = im._getexif() ctime = exifdata[0x9003] #print ctime return ctime except: _type,value,traceback = sys.exc_info() print "Error:\n%r",value return None def get_exif_prefix(jpegfn): ctime = extract_jpeg_exif_time(jpegfn) if ctime is None: return None ctime = ctime.replace(':','') ctime = re.sub('[^\d]+','_',ctime) return ctime def rename_jpeg_file(fn): if not os.path.isfile(fn): return 0 ext = os.path.splitext(fn)[1].lower() if ext not in ['.jpg','.jpeg','.jfif','.nef','.png']: return 0 path,base = os.path.split(fn) #print base # status prefix = get_exif_prefix(fn) if prefix is None: print '%s Could not be renamed' % (base) return 0 if base.startswith(prefix): print '%s file already renamed' % (base) return 0 # file already renamed to this prefix exists = True index = 0 while exists: if index == 0: new_name = prefix + ext # + '_' + base else: new_name = prefix + '_' + str(index) + ext new_full_name = os.path.join(path,new_name) exists = os.path.isfile(new_full_name) index = index + 1 if CREATE_HARDLINK: f = open('CREATE_HARDLINK.cmd','a') f.write('fsutil hardlink create "%s" "%s"\n' % (new_full_name,fn)) f.close() else: try: os.rename(fn,new_full_name) print '%s renamed to %s' % (base,new_name) except: print 'ERROR rename %s --> %s' % (fn,new_full_name) return 0 return 1 def rename_jpeg_files_in_dir(dn): names = os.listdir(dn) count=0 for n in names: file_path = os.path.join(dn,n) count += rename_jpeg_file(file_path) return count if __name__=='__main__': try: path = sys.argv[1] except IndexError: print '''Usage: rename_to_exiftime.py filename.[jpeg|jpg|jfif] or rename_to_exiftime.py dirname ''' sys.exit(1) if os.path.isfile(path): rename_jpeg_file(path) elif os.path.isdir(path): count = rename_jpeg_files_in_dir(path) print '%d file(s) renamed.' % count else: print 'ERROR: path not found: %s' % path
PIL 库下载地址: http://www.pythonware.com/products/pil/
以上是小编(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得小编网站内容还不错,欢迎将小编网站推荐给程序员好友。
今天的关于Python:从图像中删除Exif信息和python删除指定元素的分享已经结束,谢谢您的关注,如果想了解更多关于android – 从图像中删除或更新exif缩略图、javascript – 从图像中剥离EXIF数据、Java从图片中读取图片的元数据Exif信息、python利用PIL库读取图片的EXIF信息的相关知识,请在本站进行查询。
本文标签: