分類
程序

把照片重命名为拍摄时间

主要问题就是获取照片的EXIF信息中的拍摄时间。Java的话推荐Drew Noakes的metadata-extractor。python3用Pillow就行了。另外还有一个好用的python3库可以获取exif信息,EXIF.py Python3 port,短小精悍可以用在qpython3上。

实现了下java,成品和源码都在https://github.com/pggdt/rename-JPG-to-Date。先基于后缀名判断下是否是jpg文件,然后有exif信息的重命名为“年年月月日日-时时分分秒秒”格式,如果同一秒还有照片就在文件名后加1。如果勾选了重命名为最后修改时间,则会继续重命名没有exif信息的照片,将它们的名字改为图片的最后修改日期。

分類
程序

Eclipse用法

我是在ubuntu12.04上用的adt-bundle,安装好Sun Java后解压就可以使用了。关于ubuntu12.04上安装Sun Java,参考Ubuntu安装SunJava

为Eclipse安装WindowBuilder

In order to install WindowBuilder on Eclipse 4.3 (Kepler) Modeling let’s click on Help -> Install New Software… and choose (into “Work with:” field ) the main Kepler Update Site (http://download.eclipse.org/releases/kepler), expand the Category “General Purpose Tools” (make sure that “Group items by Category” flag be selected) and choose the following items:

  • SWT Designer
  • SWT Designer Core
  • WindowBuilder Core
  • WindowBuilder Core UI
  • WindowBuilder GroupLayout Support
  • WindowBuilder Java Core

Then press the Next button and follow the wizard until it asks to restart Eclipse. Let’s accept pressing Restart Now button. If you download instead the package Eclipse 4.3 (Kepler) for RCP and RAP Developers WindowBuilder is included.

分類
程序

github用法小记

github还是挺复杂的,记录下免得下次还得搜。首先按照官方文档在网页上建好项目,本地进入对应目录初始化号帐号。然后添加remote:git remote add origin_loc https://github.com/pggdt/项目名.git。然后git pull origin_loc master同步一下。最后将本地的修改提交到github:git commit可以查看本地修改过的文件。git add 文件名,可以添加等下要上传的文件。添加后再用git commit为修改做评价。最后git push origin_loc master就提交完成了。

我就是这么做的,不保证是最正确的做法,有更好意见的请提出来。

網頁註冊賬號,本地安裝git。如果想使用SSH鑒權,秩序把本機的~/.ssh/id_rsa.pub文件內容添加到https://github.com/settings/keys即可。進入要存放項目的目錄,執行git clone [email protected]:pggdt/ulogger-server.git克隆github上的項目到本地。創建cn分支來實現自己的feature git checkout -b cn。然後通過編輯器編輯代碼,完成後通過git status查看變化的文件。通過git add changedFile 來添加文件。通過 git commit -m "更新內容"來提交更新。最後推送到github上git push origin cn。

本文更新於 2018/01/25。

分類
程序

python3批量下图

又发现一个图集,用python3抓下:

import urllib.request def main(): url='http://cdn.test.com/downloads/character' path='/home/me/Pictures/paper/paper-' for i in range(1,400): ii='' if i<10: ii="00"+str(i) elif i<100: ii="0"+str(i) else: ii=str(i) url=url+ii+".jpg" print (url) h='' try: doc=urllib.request.urlopen(url) h=str(doc.info()) except urllib.error.HTTPError: print(ii+'is not exist') if('jpeg' in h): path=path+ii+".jpg" data = urllib.request.urlopen(url).read() f = open(path,"wb") f.write(data) f.close() path='/home/me/Pictures/paper/paper-' print (str(ii)+"OK") url='http://cdn.test.com/downloads/character' if __name__ == "__main__": main()[/code]

有两点改变,python2 import的是urllib,这里用到urlopen,需要import urllib.request。还有就file已经不用了,换成open就好了。getheader函数也没有了。可以对比下python2版本的另一篇python批量下图

分類
程序

python批量下图

有个网站图片很好看,网址也很有规律,但是有的是空链接。用python都下下来了。

import urllib
def main():
  url='http://static.host.com/wallpapers/picture-'
  path='/home/me/Pictures/wallpaper/picture-'
  for i in range(0,400):
    url=url+str(i)+".jpg"
    print url
    doc=urllib.urlopen(url)
    type=doc.info().getheader('Content-Type')
    if(type.find('jpeg')!=-1):
      path=path+str(i)+".jpg"
      data=urllib.urlopen(url).read()
      f=file(path,"wb")  
      f.write(data)  
      f.close()
      path='/home/me/Pictures/wallpaper/picture-'
      print str(i)+"OK"
    url='http://static.host.com/wallpapers/picture-'

if __name__ == "__main__":
  main()

本文更新於 2014/05/26。

分類
网站

让WordPress支持webp图片尺寸

在主题的image.php中(推荐复制image.php到子主题再做修改),wp_get_attachment_metadata();函数后添加如下代码:

$文件 = wp_get_attachment_url();
$文件流 = fopen($文件, "rb");
$字节数组 = fread($文件流, 30);
fclose($文件流);
$数组 = unpack("C12格式/S9尺寸", $字节数组);
for($i=9;$i&lt;=12;$i++)
{
    $文件格式.=chr($数组['格式'.$i]);
}
if(0==strcmp ( 'WEBP' , $文件格式 )){//判断是否是webp格式图片
$metadata['width'] = $数组[尺寸8];
$metadata['height'] = $数组[尺寸9];
}
通用的Java和PHP代码参见:获取WebP格式图片的长宽

本文更新於 2014/05/19。

分類
其它

获取WebP格式图片的长宽

通过查看十六进制文件,发现WebP格式图片的长宽信息位于文件头第26、27(高),28、29(宽)这四个字节中。

Java代码:

import java.io.File; import java.io.FileInputStream; /** * @author 42 */ public class WebpSize { public static void main(String[] args) { File 文件=new File("示例.webp"); try { FileInputStream 输入=new FileInputStream(文件); byte[] 字节数组=new byte[30]; 输入.read(字节数组); if("WEBP".equals(new String(字节数组,8,4,"utf-8"))){//先判断图片格式为webp int 宽 = (((int) 字节数组[27] & 0xff) << 8) | (int) 字节数组[26] & 0xff; int 高 = (((int) 字节数组[29] & 0xff) << 8) | (int) 字节数组[28] & 0xff; System.out.print("宽:"+宽+",高:"+高); }else{ System.out.print("文件不是webp格式"); } 输入.close(); } catch(Exception e) { System.out.println(e.getMessage()); } } }[/code]

本文更新於 2014/05/19。