??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品久久久www,久久青青草原精品国产不卡,久久精品人人做人人爽电影蜜月 http://m.shnenglu.com/sunrise/每天不断学习(fn)Q才能不断提升自己?/description>zh-cnSat, 28 Jun 2025 00:04:03 GMTSat, 28 Jun 2025 00:04:03 GMT60解决MySQL 1366 Incorrect string valuehttp://m.shnenglu.com/sunrise/archive/2013/04/16/199476.htmlSunRise_atSunRise_atTue, 16 Apr 2013 03:34:00 GMThttp://m.shnenglu.com/sunrise/archive/2013/04/16/199476.htmlhttp://m.shnenglu.com/sunrise/comments/199476.htmlhttp://m.shnenglu.com/sunrise/archive/2013/04/16/199476.html#Feedback0http://m.shnenglu.com/sunrise/comments/commentRss/199476.htmlhttp://m.shnenglu.com/sunrise/services/trackbacks/199476.html刚开始的时候设|了(jin)我的myslq如下Q?br />
所以一直以为是我的E序问题Q然后一直改啊改啊,最后才发现mysql的数据库建的字符集还是没有修改然后执行如下操作就O(jin)K?jin)?x)
mysql> use designer
Database changed
mysql> alter database designer character set utf-8;
ERROR 1115 (42000): Unknown character set'utf'
mysql> alter database yourdatabase character set utf8;


SunRise_at 2013-04-16 11:34 发表评论
]]>
jQuery插gQuickPaginate快速分实?/title><link>http://m.shnenglu.com/sunrise/archive/2013/03/14/198418.html</link><dc:creator>SunRise_at</dc:creator><author>SunRise_at</author><pubDate>Thu, 14 Mar 2013 06:54:00 GMT</pubDate><guid>http://m.shnenglu.com/sunrise/archive/2013/03/14/198418.html</guid><wfw:comment>http://m.shnenglu.com/sunrise/comments/198418.html</wfw:comment><comments>http://m.shnenglu.com/sunrise/archive/2013/03/14/198418.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/sunrise/comments/commentRss/198418.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/sunrise/services/trackbacks/198418.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;">介绍一个分|Ӟ那么什么叫QuickPaginate快速分,q个插g实现是需要显C的内容用分늚Ҏ(gu)昄Q但不是真正意义上的分页Q?因ؓ(f)QuickPaginate快速分不需要与服务器端交互Q所有的内容已经全部输送到客户端,每次昄部分信息Q用分页的Ş式进行浏览,效果囑֦下:(x)<br /><br /><strong>使用说明</strong><br />一Q需?a target="_blank" style="color: #1e375a;">jQuery库文?/a>?a target="_blank" style="color: #1e375a;">QuickPaginate库文?/a><br />二,可自定义分页CSS昄效果Q如Qqp_prev和qp_next</p><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;"><strong>使用实例</strong><br />一Q包含文仉?/p><ol style="margin: 0px; padding: 0px; list-style: none; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;"><li style="margin: 0px; padding: 0px;"><script src="jquery.js" type="text/javascript" ></script></li><li style="margin: 0px; padding: 0px;"><script src="jquery.quickpaginate.js" type="text/javascript" ></script></li></ol><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;">二,HTML部分<br />(1)jQuery插gQuickPaginate实现<strong>文本</strong>分页功能</p><ol style="margin: 0px; padding: 0px; list-style: none; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;"><li style="margin: 0px; padding: 0px;"><ul id="<strong>biuuu_city_list</strong>"></li><li style="margin: 0px; padding: 0px;"><li>北京</li></li><li style="margin: 0px; padding: 0px;"><li>上v</li></li><li style="margin: 0px; padding: 0px;"><li>q州</li></li><li style="margin: 0px; padding: 0px;"><li>杭州</li></li><li style="margin: 0px; padding: 0px;"><li>长沙</li></li><li style="margin: 0px; padding: 0px;"><li>合肥</li></li><li style="margin: 0px; padding: 0px;"><li>宁夏</li></li><li style="margin: 0px; padding: 0px;"><li>成都</li></li><li style="margin: 0px; padding: 0px;"><li>西安</li></li><li style="margin: 0px; padding: 0px;"><li>南昌</li></li><li style="margin: 0px; padding: 0px;"></ul></li><li style="margin: 0px; padding: 0px;"><div id="<strong>biuuu_city</strong>"></div></li></ol><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;">其中ID为biuuu_city_list的DIV是要实现分页的内容,ID为biuuu_city是显C分内容,具体看效果图</p><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;">(2)jQuery插gQuickPaginate实现<strong>囄</strong>分页功能</p><ol style="margin: 0px; padding: 0px; list-style: none; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;"><li style="margin: 0px; padding: 0px;"><div id="<strong>images</strong>"></li><li style="margin: 0px; padding: 0px;"><img src="demo_images/demo1.jpg" width="200" height="133" alt="biuuu1" /></li><li style="margin: 0px; padding: 0px;"><img src="demo_images/demo2.jpg" width="200" height="133" alt="biuuu2" /></li><li style="margin: 0px; padding: 0px;"><img src="demo_images/demo3.jpg" width="200" height="133" alt="biuuu3" /></li><li style="margin: 0px; padding: 0px;"></div></li><li style="margin: 0px; padding: 0px;"><div id="<strong>images_counter</strong>"></div></li></ol><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;">三,javascript部分(调用jQuery插gQuickPaginate)</p><ol style="margin: 0px; padding: 0px; list-style: none; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;"><li style="margin: 0px; padding: 0px;"><script type="text/javascript"></li><li style="margin: 0px; padding: 0px;">$(function(){</li><li style="margin: 0px; padding: 0px;">$("#<strong>biuuu_city_list li</strong>").<strong>quickpaginate</strong>({ <strong>perpage</strong>: 4, <strong>pager </strong>: $("#<strong>biuuu_city</strong>") });</li><li style="margin: 0px; padding: 0px;">});</li><li style="margin: 0px; padding: 0px;">$(function(){</li><li style="margin: 0px; padding: 0px;">$("<strong>#images img</strong>").<strong>quickpaginate</strong>({ <strong>perpage</strong>: 1, <strong>showcounter</strong>: false, <strong>pager </strong>: $("<strong>#images_counter</strong>") });</li><li style="margin: 0px; padding: 0px;">});</li><li style="margin: 0px; padding: 0px;"></script></li></ol><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;"><strong>jQuery插gQuickPaginate参数详解</strong><br />perpage表示每页昄敎ͼ默认gؓ(f)6Q如上文本实例每|C?个城?jng),囄实例每页昄?张图?br />pager表示QuickPaginate生成分页HTML代码昄的对象,默认为nullQ如上:(x)$("#biuuu_city")?("#images_counter")<br />showcounter表示是否昄l计Q默认ؓ(f)true<br />prev表示上一CSS样式名,默认为qp_nextQ具体请看QuickPaginate生成的代码图<br />next表示下一CSS样式名,默认为qp_prev<br />pagenumber表示当前CSS样式名,默认为qp_pagenumber<br />totalnumber表示总页数CSS样式名,默认为qp_totalnumber<br />counter表示l计CSS样式名,默认为qp_counter</p><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;">注意事项<br />注意默认的QuickPaginate是UTF8~码Q同旉要修攚w分QuickPaginate的JS库代码,如将prev修改Z文上一,next修改Z文下一,其实是分页样式Q上面的参数中大部分都是定义某个部分的样式,因ؓ(f)样式也是非常重要的?/p><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;">以上实例可知使用jQuery插gQuickPaginate快速分非常简单,只需要指定内容,指定每页昄敎ͼ昄样式Q即可实现快速分功能,在实际应用中Q可对菜单、图片等q行分页Q非常具有实用性,值得推荐?/p><p style="margin: 0px; padding: 0px; color: #454545; font-family: tahoma, helvetica, arial; background-color: #ffffff;"><a target="_blank" style="color: #1e375a;">Ҏ(gu)下蝲jQuery插gQuickPaginate快速分늨?/a><br /><a target="_blank" style="color: #1e375a;">Ҏ(gu)查看jQuery插gQuickPaginate快速分面演C?/a></p><img src ="http://m.shnenglu.com/sunrise/aggbug/198418.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/sunrise/" target="_blank">SunRise_at</a> 2013-03-14 14:54 <a href="http://m.shnenglu.com/sunrise/archive/2013/03/14/198418.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>turbogear2上传文g功能http://m.shnenglu.com/sunrise/archive/2013/03/12/198363.htmlSunRise_atSunRise_atTue, 12 Mar 2013 09:07:00 GMThttp://m.shnenglu.com/sunrise/archive/2013/03/12/198363.htmlhttp://m.shnenglu.com/sunrise/comments/198363.htmlhttp://m.shnenglu.com/sunrise/archive/2013/03/12/198363.html#Feedback0http://m.shnenglu.com/sunrise/comments/commentRss/198363.htmlhttp://m.shnenglu.com/sunrise/services/trackbacks/198363.html
<form  id="upload"  action="/designer/uploadandcut" method="post" enctype="multipart/form-data">
                <input type="file" name="headimage" id="headimage" style= "display:none"/>
</form>   




后台代码Q?br />
   #上传和剪?/div>
   @expose()
   def uploadandcut(self,username,headimage):
       print 'run'
       permanent_file = open(os.getcwd()+"\\designerpage\\public\\"+username+"\\headimage\\headimage.png",'wb')
       print permanent_file
       shutil.copyfileobj(headimage.file,permanent_file)
       headimage.file.close()
       permanent_file.close()
       redirect("/designer/designerMyIndex")


SunRise_at 2013-03-12 17:07 发表评论
]]>关于PIL库的一些概?/title><link>http://m.shnenglu.com/sunrise/archive/2013/03/02/198174.html</link><dc:creator>SunRise_at</dc:creator><author>SunRise_at</author><pubDate>Sat, 02 Mar 2013 08:04:00 GMT</pubDate><guid>http://m.shnenglu.com/sunrise/archive/2013/03/02/198174.html</guid><wfw:comment>http://m.shnenglu.com/sunrise/comments/198174.html</wfw:comment><comments>http://m.shnenglu.com/sunrise/archive/2013/03/02/198174.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/sunrise/comments/commentRss/198174.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/sunrise/services/trackbacks/198174.html</trackback:ping><description><![CDATA[<p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><strong>转自Q?/strong>http://www.iteye.com/topic/314790<strong><br /></strong><strong>pil能处理的囄</strong><strong>cd</strong><br />pil可以处理光栅囄(像素数据l成的的??br /><br /><strong>通道</strong><br />一个图片可以包含一到多个数据通道Q如果这些通道h相同的维数和深度QPil允许这些通道q行叠加<br /><br /><strong>模式</strong></p><table width="322" border="1" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.1875px; background-color: #efefef; border-color: #000000; height: 207px;"><tbody><tr><td style="font-size: 1em; padding: 5px;">1</td><td style="font-size: 1em; padding: 5px;"> 1位像素,黑和白,存成8位的像素</td></tr><tr><td style="font-size: 1em; padding: 5px;">L</td><td style="font-size: 1em; padding: 5px;"> 8位像素,黑白</td></tr><tr><td style="font-size: 1em; padding: 5px;">P</td><td style="font-size: 1em; padding: 5px;"> 8位像素,使用调色板映到M其他模式</td></tr><tr><td style="font-size: 1em; padding: 5px;">RGB</td><td style="font-size: 1em; padding: 5px;"> 3×8位像素,真彩</td></tr><tr><td style="font-size: 1em; padding: 5px;">RGBA</td><td style="font-size: 1em; padding: 5px;"> 4×8位像素,真彩+透明通道</td></tr><tr><td style="font-size: 1em; padding: 5px;">CMYK</td><td style="font-size: 1em; padding: 5px;"> 4×8位像素,颜色隔离</td></tr><tr><td style="font-size: 1em; padding: 5px;">YCbCr</td><td style="font-size: 1em; padding: 5px;"> 3×8位像素,彩色视频格式</td></tr><tr><td style="font-size: 1em; padding: 5px;">I</td><td style="font-size: 1em; padding: 5px;"> 32位整型像?/td></tr><tr><td style="font-size: 1em; padding: 5px;">F</td><td style="font-size: 1em; padding: 5px;"> 32位Q点型像素</td></tr><tr><td style="font-size: 1em; padding: 5px;"><br /></td><td style="font-size: 1em; padding: 5px;"><br /></td></tr></tbody></table><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><br /><strong>寸</strong><br />通过囄对象的size属性可以得到图片的寸Q结果这是一个二元组Q包含水q_垂直方向上的像素数?br /><br /><strong>坐标</strong><br />Pil采取左上角ؓ(f)(0,0)的坐标系l?br /><br /><strong>调色?/strong><br />mode("P")为每个像素定义具体的颜色?br /><br /><strong>囄信息</strong><br />可以通过info属性读取一张图片的附加信息Q这个与囄的格式有兟?br /><br /><strong>滤镜</strong><br />在对囄的几何操作中可能?x)将多个输入像素映射到单个的输出像素Qpil提供4U不同的采样滤镜(在目前的版本中,后箋的版本可能支持更?</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> </p><table border="1" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25.1875px; background-color: #efefef; border-color: #000000;"><tbody><tr><td style="font-size: 1em; padding: 5px;">NEAREST</td><td style="font-size: 1em; padding: 5px;">最q?/td></tr><tr><td style="font-size: 1em; padding: 5px;">BILINEAR</td><td style="font-size: 1em; padding: 5px;">双线?/td></tr><tr><td style="font-size: 1em; padding: 5px;">BICUBIC</td><td style="font-size: 1em; padding: 5px;">双三ơ插?/td></tr><tr><td style="font-size: 1em; padding: 5px;">ANTIALIAS</td><td style="font-size: 1em; padding: 5px;">qx(chng)</td></tr></tbody></table><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;">在RGB模式下,每个囄׃个通道叠加而成Q每个模式下Z个灰度图Q当有一个调色板来调色的时候,q三张灰度图的叠加即可合?*8?每个像素)的一个真彩图片。pil库中Q图片之间的模式(mode)可以转化。下面给Z些简单的例子Q例子中的所有图片均来自于国家地理的官网Qؓ(f)?jin)得文档比较短,每个囄均用Pil~放?/2大小Q如有R权嫌疑,请尽快联p,我会(x)删除q些囄?br /><br />所有的囄操作必须有一个操作对象,Pil提供<em>open(filename)</em>q行q个q程</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><strong>打开囄</strong><br />1.导入pil的Image模块<br />2.使用open(filename)打开文gQ返回一个image对象</p><div class="9dvzr7t" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=im%20%3D%20Image.open('filename')" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">im = Image.open('filename')  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br />此后Q一切关于图片的操作均基于这个对象?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><img alt="" src="http://www.iteye.com/upload/attachment/67907/9d59e028-a64d-38b5-86a9-17f1c458d4e5.jpg" style="border: 0px;" /><br /> <br /><br />打开后,我们可以查看一些图片信息,如im.format, im.size, im.mode{。调用im.show()?x)在囄查看工具中显C当前操作的image对象Q这个跟个h的系l有关系Q我pȝ中默认是用Windows Picture and Fax Viewer打开的。这个方法用来查看(f)时的囄效果?br /><br /><strong>d囄</strong><br />pil中{换图片格式非常简?转换囄模式是另一个概念,不要h)Q只需要调用img.save(filename)卛_比如有一个bmp(位图)囄Q用img = Image.open('file.bmp')打开后,只需要img.save('file.jpg')卛_转换。不q一般情况下Qsave(filename)是不用做q个用途的Q通常Qsave用以保存?sh)个(f)时的image对象到硬盘。而{换工作由一个功能更为强大的convert()Ҏ(gu)来完成?br /><br /><strong><br />拯Q粘_(d)合ƈ</strong></p><div class="jj9vv1z" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=box%20%3D%20(100%2C100%2C500%2C500)%23%E8%AE%BE%E7%BD%AE%E8%A6%81%E6%8B%B7%E8%B4%9D%E7%9A%84%E5%8C%BA%E5%9F%9F%0A%0A%23%E5%B0%86im%E8%A1%A8%E7%A4%BA%E7%9A%84%E5%9B%BE%E7%89%87%E5%AF%B9%E8%B1%A1%E6%8B%B7%E8%B4%9D%E5%88%B0region%E4%B8%AD%EF%BC%8C%E5%A4%A7%E5%B0%8F%E4%B8%BA(400*400)%E5%83%8F%E7%B4%A0%E3%80%82%E8%BF%99%E4%B8%AAregion%E5%8F%AF%E4%BB%A5%E7%94%A8%E6%9D%A5%E5%90%8E%E7%BB%AD%E7%9A%84%E6%93%8D%E4%BD%9C(region%E5%85%B6%E5%AE%9E%E5%B0%B1%E6%98%AF%E4%B8%80%E4%B8%AAImage%E5%AF%B9%E8%B1%A1)%EF%BC%8Cbox%E5%8F%98%E9%87%8F%E6%98%AF%E4%B8%80%E4%B8%AA%E5%9B%9B%E5%85%83%E7%BB%84(%E5%B7%A6%EF%BC%8C%E4%B8%8A%EF%BC%8C%E5%8F%B3%EF%BC%8C%E4%B8%8B)%E3%80%82%0Aregion%20%3D%20im.crop(box)%0A%0Aregion%20%3D%20region.transpose(Image.ROTATE_180)%23%E4%BB%8E%E5%AD%97%E9%9D%A2%E4%B8%8A%E5%B0%B1%E5%8F%AF%E4%BB%A5%E7%9C%8B%E5%87%BA%EF%BC%8C%E5%85%88%E6%8A%8Aregion%E4%B8%AD%E7%9A%84Image%E5%8F%8D%E8%BD%AC180%E5%BA%A6%EF%BC%8C%E7%84%B6%E5%90%8E%E5%86%8D%E6%94%BE%E5%9B%9E%E5%88%B0region%E4%B8%AD%E3%80%82%0Aim.paste(region%2C%20box)%23%E7%B2%98%E8%B4%B4box%E5%A4%A7%E5%B0%8F%E7%9A%84region%E5%88%B0%E5%8E%9F%E5%85%88%E7%9A%84%E5%9B%BE%E7%89%87%E5%AF%B9%E8%B1%A1%E4%B8%AD%E3%80%82" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">box = (100,100,500,500)<span style="width: auto; border-width: 0px;">#讄要拷贝的区域</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="width: auto; border-width: 0px;">#im表示的图片对象拷贝到region中,大小?400*400)像素。这个region可以用来后箋的操?region其实是一个Image对象)Qbox变量是一个四元组(左,上,叻I??/span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">region = im.crop(box)  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">region = region.transpose(Image.ROTATE_180)<span style="width: auto; border-width: 0px;">#从字面上可以看出,先把region中的Image反{180度,然后再放回到region中?/span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">im.paste(region, box)<span style="width: auto; border-width: 0px;">#_脓(chung)box大小的region到原先的囄对象中?/span>  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> <br /><img alt="" src="http://www.iteye.com/upload/attachment/67929/23e23659-c9d6-391a-a5c0-642a0da0da3b.jpg" style="border: 0px;" /></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;">前面说过Q每一个RGB都是׃个通道的灰度图叠加的,所以pil提供?jin)将q三个通道分离的方?/p><div class="9vrft9d" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=r%2Cg%2Cb%20%3D%20im.split()%23%E5%88%86%E5%89%B2%E6%88%90%E4%B8%89%E4%B8%AA%E9%80%9A%E9%81%93%0Ar.show()%0Ag.show()%0Ab.show()%0Aim%20%3D%20Image.merge(%22RGB%22%2C%20(b%2C%20g%2C%20r))%23%E5%B0%86b%2Cr%E4%B8%A4%E4%B8%AA%E9%80%9A%E9%81%93%E8%BF%9B%E8%A1%8C%E7%BF%BB%E8%BD%AC%E3%80%82" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">r,g,b = im.split()<span style="width: auto; border-width: 0px;">#分割成三个通道</span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">r.show()  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">g.show()  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">b.show()  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">im = Image.merge("RGB", (b, g, r))<span style="width: auto; border-width: 0px;">#b,r两个通道q行{?/span>  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> <br /><img alt="" src="http://www.iteye.com/upload/attachment/67917/aded3d14-6b02-3c4e-8b6b-721e6c0513ac.jpg" style="border: 0px;" /></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;">U色通道的灰度图</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><img alt="" src="http://www.iteye.com/upload/attachment/67915/ab65be22-fd70-3a83-876e-7540d50b0516.jpg" style="border: 0px;" /><br /> l色通道的灰度图</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><img alt="" src="http://www.iteye.com/upload/attachment/67913/78d2e95c-de7e-3435-aff2-3a553fd9199d.jpg" style="border: 0px;" /><br /> 蓝色通道的灰度图</p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><img alt="" src="http://www.iteye.com/upload/attachment/67921/228d018c-3a4c-382d-911f-e363616f7d2c.jpg" style="border: 0px;" /><br /> <br /> 互换U蓝通道后的合成?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><strong>几何转变</strong><br />几何转变提供resize,rotate{方法,用以重定义图片大,对图片进行旋转等操作Q在实际应用中比较广泛?br /><br />?/p><div class="hv7jn99" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=%20%20%20out%20%3D%20img.resize((128%2C%20128))%23resize%E6%88%90128*128%E5%83%8F%E7%B4%A0%E5%A4%A7%E5%B0%8F%E3%80%82%0A%20%20%20out%20%3D%20img.rotate(45)%23%E9%80%86%E6%97%B6%E9%92%88%E6%97%8B%E8%BD%AC45%E5%BA%A6" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">out = img.resize((128, 128))<span style="width: auto; border-width: 0px;">#resize?28*128像素大小?/span>  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">out = img.rotate(45)<span style="width: auto; border-width: 0px;">#逆时针旋?5?/span>  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><img alt="" src="http://www.iteye.com/upload/attachment/67931/d78bd43c-edff-34f1-8e24-ff4864ad7ebf.jpg" style="border: 0px;" /></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;">逆时?5?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><img alt="" src="http://www.iteye.com/upload/attachment/67923/153f70f2-ef4a-305b-8f19-1c5c50afed03.jpg" style="border: 0px;" /><br /> <br /> 镜面效果Q左右翻?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;">transpose()Ҏ(gu)预定义了(jin)一些旋转方式,?br />左右反{Q上下翻转,逆时针旋?90,180,270)度等Q非常方便,rotate()和transpose()Ҏ(gu)在表C没有M不同?br /><br /><strong>囄加强</strong></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><em>滤镜</em><br />ImageFilter模块提供?jin)很多预定义的图片加强o(h)镜?br />比如一个常用的滤镜,l节(detail滤镜)</p><div class="t9d9hr9" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=import%20ImageFilter%0Aout%20%3D%20im.filter(ImageFilter.DETAIL)" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span> ImageFilter  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">out = im.filter(ImageFilter.DETAIL)  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><img alt="" src="http://www.iteye.com/upload/attachment/67927/15d69cfb-4f77-35f2-a71f-30b2943d70da.jpg" style="border: 0px;" /><br /> <br /><br /><em>直接操作像素?/em><br />不但可以Ҏ(gu)个像素点q行操作Q而且Q每一个通道都可以独立的q行操作。比如,每个像素点的亮?不知道有没有更专业的?增大20%</p><div class="njp9799" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=out%20%3D%20img.point(lambda%20i%20%3A%20i%20*%201.2)%23%E6%B3%A8%E6%84%8F%E8%BF%99%E9%87%8C%E7%94%A8%E5%88%B0%E4%B8%80%E4%B8%AA%E5%8C%BF%E5%90%8D%E5%87%BD%E6%95%B0(%E9%82%A3%E4%B8%AA%E5%8F%AF%E4%BB%A5%E6%8A%8Ai%E7%9A%841.2%E5%80%8D%E8%BF%94%E5%9B%9E%E7%9A%84%E5%87%BD%E6%95%B0)" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">out = img.point(<span style="color: #7f0055;">lambda</span> i : i * 1.2)<span style="width: auto; border-width: 0px;">#注意q里用到一个匿名函?那个可以把i?.2倍返回的函数)</span>  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><img alt="" src="http://www.iteye.com/upload/attachment/67919/ef666066-02b8-3fb1-b8d7-ec0062f57c44.jpg" style="border: 0px;" /><br />Ҏ(gu)个点都做20%的增?/p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;">如上边的那个例子Q我们可以将一个RGB模式的图分离成三个通道的层</p><div class="nzzhbn7" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=r%2Cg%2Cb%20%3D%20img.split()%23%E7%A5%9E%E5%A5%87%E8%80%8C%E5%8F%88%E5%BC%BA%E5%A4%A7%E7%9A%84python%E8%AF%AD%E6%B3%95" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">r,g,b = img.split()<span style="width: auto; border-width: 0px;">#奇而又强大的python语法</span>  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><br />然后对一个通道q行加强或减弱操作,完成后我们又可以使用Merge通道合ƈQ从而改变图片的色调(h色调的互?{?br /><br />更高U的囄加强Q可以用ImageEnhance模块Q其中包含了(jin)大量的预定义的图片加强方式?/p><div class="nxzv9hh" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=import%20ImageEnhance%0Aenh%20%3D%20ImageEnhance.Contrast(im)%0Aenh.ehhance(1.5).show(%2250%25%20more%20contrast%22)" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span> ImageEnhance  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">enh = ImageEnhance.Contrast(im)  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">enh.ehhance(1.5).show("50% more contrast")  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><img alt="" src="http://www.iteye.com/upload/attachment/67925/32acbe28-f089-31a6-990f-3d0e4a790486.jpg" style="border: 0px;" /></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><em>d囄的更多方?/em><br />通常Q我们用openҎ(gu)q行囄的打开操作。但是这不是唯一的方式。完全可以跟python的IO整合h。如</p><div class="z9hn979" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=fp%20%3D%20open(%22file.jpg%22%2C%20%22rb%22)%0Aim%20%3D%20Image.open(fp)" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">fp = open("file.jpg", "rb")  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">im = Image.open(fp)  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;">甚至Q你可以从一个字W串中读出图片数据来(<span style="color: #3366ff;">python真是奇?/span>)?/p><div class="p1xrpz9" id="" style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; background-color: #efefef; width: 766.296875px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.1875px;"><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold;">Python代码 <embed wmode="transparent" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" width="14" height="15" flashvars="clipboard=import%20StringIO%0Aimg%20%3D%20Image.open(StringIO.StringIO(buffer))" quality="high" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"> <a href="" title="收藏q段代码" style="color: #006699;"><img src="http://www.iteye.com/images/icon_star.png" alt="收藏代码" style="border: 0px;" /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af;"><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;"><span style="color: #7f0055;">import</span> StringIO  </li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px;">img = Image.open(StringIO.StringIO(buffer))  </li></ol></div><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"><br /><span style="text-decoration: underline;">(文中很多内容来自pil的handbookQ但是原手册比较学院z,没有一张图片来q行说明Q因此不免枯燥,我给每个例子都加上一个真实的囄作ؓ(f)说明Q希望看h不那没抽象?</span></p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;"> </p><p style="margin: 0px; padding: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.1875px; background-color: #efefef;">当然QPIL的功能远不止q些Q由于篇q原因,我这ơ先写这么多吧,后面?x)给出PIL中各个模块中函数的详l用说明,同时量配以实图来说明?/p><img src ="http://m.shnenglu.com/sunrise/aggbug/198174.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/sunrise/" target="_blank">SunRise_at</a> 2013-03-02 16:04 <a href="http://m.shnenglu.com/sunrise/archive/2013/03/02/198174.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UnicodeDecodeError: 'utf8' codec can't decode bytes in position 18-19: unexpected end of datahttp://m.shnenglu.com/sunrise/archive/2013/02/21/197977.htmlSunRise_atSunRise_atThu, 21 Feb 2013 08:39:00 GMThttp://m.shnenglu.com/sunrise/archive/2013/02/21/197977.htmlhttp://m.shnenglu.com/sunrise/comments/197977.htmlhttp://m.shnenglu.com/sunrise/archive/2013/02/21/197977.html#Feedback2http://m.shnenglu.com/sunrise/comments/commentRss/197977.htmlhttp://m.shnenglu.com/sunrise/services/trackbacks/197977.html本来是ؓ(f)?jin)省事处理数据的时候批量插入,l果插入的时候一直不能decode?br />python代码Q?
a=open(r"testdata.txt").read(20)
print list(a)
print '=========================================================================================='
print list(a.decode('utf8'))
print '=========================================================================================='
testdata数据Q?
0 1 test qg衣服设计的正好看Q正是我惌?2013/2/23 zh
0
2 happys qg衣服设计的正好看Q正是我惌?2013/11/21 zh

出现的错误:(x)
['\xef', '\xbb', '\xbf', '0', '\t', '1', '\t', 't', 'e', 's', 't', '\t', '\xe8', '\xbf', '\x99', '\xe4', '\xbb', '\xb6', '\xe8', '\xa1']
==========================================================================================

Traceback (most recent call last):
File
"E:/designerpage/test.py", line 4, in <module>
print list(a.decode('utf8'))
File
"D:\Python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError:
'utf8' codec can't decode bytes in position 18-19: unexpected end of data
出现错误的原因是因ؓ(f)utf8格式一般是'\xef', '\xbb', '\xbf'三个一起出玎ͼ然后解析的,而在某处不能够成三个一l的时候就?x)出现这L(fng)错误。如果将20改ؓ(f)18则可以正常执行?br />当然如果是在python2.6里是可以q行的,python2.7׃(x)出现如上错误。无比坑爹的bug,查了(jin)好久?br />


SunRise_at 2013-02-21 16:39 发表评论
]]>
access violation at address 解决之法http://m.shnenglu.com/sunrise/archive/2013/02/21/197973.htmlSunRise_atSunRise_atThu, 21 Feb 2013 03:04:00 GMThttp://m.shnenglu.com/sunrise/archive/2013/02/21/197973.htmlhttp://m.shnenglu.com/sunrise/comments/197973.htmlhttp://m.shnenglu.com/sunrise/archive/2013/02/21/197973.html#Feedback0http://m.shnenglu.com/sunrise/comments/commentRss/197973.htmlhttp://m.shnenglu.com/sunrise/services/trackbacks/197973.html叛_“我的?sh)?#8221;。单?#8220;属?#8221;?/p>

?#8220;pȝ属?#8221;中单?#8220;高”?/p>

?#8220;性能”中单?#8220;讄”?/p>

?#8220;性能选项”中单?#8220;数据执行保护”?/p>

单击“d”。选择要运行的E序?/p>

SunRise_at 2013-02-21 11:04 发表评论
]]>
python的默认参?/title><link>http://m.shnenglu.com/sunrise/archive/2013/01/17/197350.html</link><dc:creator>SunRise_at</dc:creator><author>SunRise_at</author><pubDate>Thu, 17 Jan 2013 09:43:00 GMT</pubDate><guid>http://m.shnenglu.com/sunrise/archive/2013/01/17/197350.html</guid><wfw:comment>http://m.shnenglu.com/sunrise/comments/197350.html</wfw:comment><comments>http://m.shnenglu.com/sunrise/archive/2013/01/17/197350.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.shnenglu.com/sunrise/comments/commentRss/197350.html</wfw:commentRss><trackback:ping>http://m.shnenglu.com/sunrise/services/trackbacks/197350.html</trackback:ping><description><![CDATA[刚在里一个h问的问题Q前两天正好看过Q记录一下? <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #800080">__author__</span><span style="color: #000000"> </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #800000">'</span><span style="color: #800000">chenyu</span><span style="color: #800000">'</span><span style="color: #000000"><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">def</span><span style="color: #000000"> f(i,L</span><span style="color: #000000">=</span><span style="color: #000000">[]):<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />    L.append(i)<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> L<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">def</span><span style="color: #000000"> f2(i,L</span><span style="color: #000000">=</span><span style="color: #000000">None):<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />    </span><span style="color: #0000ff">if</span><span style="color: #000000"> L  </span><span style="color: #0000ff">is</span><span style="color: #000000"> None:<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />       L </span><span style="color: #000000">=</span><span style="color: #000000"> []<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />    L.append(i)<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> L<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">print</span><span style="color: #000000"> f(</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">print</span><span style="color: #000000"> f(</span><span style="color: #000000">2</span><span style="color: #000000">)<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">print</span><span style="color: #000000"> f(</span><span style="color: #000000">3</span><span style="color: #000000">)<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">print</span><span style="color: #000000"> f2(</span><span style="color: #000000">1</span><span style="color: #000000">)<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">print</span><span style="color: #000000"> f2(</span><span style="color: #000000">2</span><span style="color: #000000">)<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /></span><span style="color: #0000ff">print</span><span style="color: #000000"> f2(</span><span style="color: #000000">3</span><span style="color: #000000">)</span></div>输出Q?br /> <div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" /><span style="color: #000000">[</span><span style="color: #000000">1</span><span style="color: #000000">]<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />[</span><span style="color: #000000">1</span><span style="color: #000000">, </span><span style="color: #000000">2</span><span style="color: #000000">]<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />[</span><span style="color: #000000">1</span><span style="color: #000000">, </span><span style="color: #000000">2</span><span style="color: #000000">, </span><span style="color: #000000">3</span><span style="color: #000000">]<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />[</span><span style="color: #000000">1</span><span style="color: #000000">]<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />[</span><span style="color: #000000">2</span><span style="color: #000000">]<br /><img align="top" src="http://m.shnenglu.com/images/OutliningIndicators/None.gif" alt="" />[</span><span style="color: #000000">3</span><span style="color: #000000">]</span></div>按照预想的结果f()输出的应该是[1],[2],[3],但是每次上次的结果都被保留下来了(jin)?br />造成q样的原因是python支持函数中的参数默认值是一个可变的list, 函数体内修改?jin)原来的默认|而python?x)将修改后的g直保留,q作Zơ函数调用时的参数默认倹{?img src ="http://m.shnenglu.com/sunrise/aggbug/197350.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.shnenglu.com/sunrise/" target="_blank">SunRise_at</a> 2013-01-17 17:43 <a href="http://m.shnenglu.com/sunrise/archive/2013/01/17/197350.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Google Translate API http://m.shnenglu.com/sunrise/archive/2013/01/17/197348.htmlSunRise_atSunRise_atThu, 17 Jan 2013 08:59:00 GMThttp://m.shnenglu.com/sunrise/archive/2013/01/17/197348.htmlhttp://m.shnenglu.com/sunrise/comments/197348.htmlhttp://m.shnenglu.com/sunrise/archive/2013/01/17/197348.html#Feedback0http://m.shnenglu.com/sunrise/comments/commentRss/197348.htmlhttp://m.shnenglu.com/sunrise/services/trackbacks/197348.htmlq期在做的一个Q务,但是|上的资料甚,l过?jin)几番L折,l于弄好?jin)。实现过E很单,拿出来共享一下,免得大家像我一h?jin)半天?br />
h译升?.0后变?sh)收费版本的Q因此首先需要向h甌一个key。付Ҏ(gu)准是?00万个文本字符20元Q觉得小贵啦Q?br />
h译的工作过E:(x)
1.h译的请求网址Q?
https://www.googleapis.com/language/translate/v2?{parameters}
译h的三个参敎ͼ(x)
1)API key:需要向h付费后,?x)给你一个key;
2)Target language:即你需要翻译的目标语言;
3)Source text string:需要翻译的文本(需要少?k)?br />
2.下面是给不同的参数的一些例子,可以Ҏ(gu)自己的需要来对该urlq行传参Q?br />1)指定source和target
https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world
JSON
{
"data": {
"translations": [
{
"translatedText": "Hallo Welt"
}
]
}
}
2)传入多个q,对多段文本q行译
https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=de&q=Hello%20world&q=My%20name%20is%20Jeff
JSON
{
"data": {
"translations": [
{
"translatedText": "Hallo Welt"
},
{
"translatedText": "Mein Name ist Jeff"
 }
]
}
}
3)不指定source,直接译成目标语a
https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&target=de&q=Hello%20world
JSON
{
"data": {
"translations": [
{
"translatedText": "Hallo Welt",
"detectedSourceLanguage": "en"
}
]
}
}
3.python实现的谷歌翻译源码:(x)
#coding:utf8


import urllib2
import json
import os,sys

reload(sys)
sys.setdefaultencoding(
"utf-8")

__author__ = 'chenyu'

class GoogleTranslate:
"""
h译c?br />
"""
def google_translate(slef,text,targetlanguage):
text
= urllib2.quote(text)
url
= "https://www.googleapis.com/language/translate/v2/?key=YOUR_KEY&target="+targetlanguage+"&q="+text
res
= urllib2.urlopen(urllib2.Request(url))
dirt
= json.JSONDecoder().decode(res.read())
return dirt["data"]["translations"][0]["translatedText"]

参见|站Q?a >https://developers.google.com/translate/v2/using_rest?hl=zh-TW#target
JSON相关资料可参见:(x)http://m.shnenglu.com/sunrise/archive/2013/01/17/197347.html




SunRise_at 2013-01-17 16:59 发表评论
]]>
json的编码和解析http://m.shnenglu.com/sunrise/archive/2013/01/17/197347.htmlSunRise_atSunRise_atThu, 17 Jan 2013 08:28:00 GMThttp://m.shnenglu.com/sunrise/archive/2013/01/17/197347.htmlhttp://m.shnenglu.com/sunrise/comments/197347.htmlhttp://m.shnenglu.com/sunrise/archive/2013/01/17/197347.html#Feedback0http://m.shnenglu.com/sunrise/comments/commentRss/197347.htmlhttp://m.shnenglu.com/sunrise/services/trackbacks/197347.html


  JSON
?a class="wikilink2" title="modules:javascript" rel="nofollow">JavaScript Object Notation的羃写,SJON是一U轻量的数据交换格式。易于h阅读和编写。同时也易于机器解析和生成?

它基?a class="wikilink2" title="modules:javascript" rel="nofollow">JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999的一个子集?/p>

   JSON建构于两U结构:(x)

“名称/?#8221;对的集合QA collection of name/value pairsQ。不同的语言中,它被理解为对象(objectQ,U录QrecordQ,l构QstructQ,字典QdictionaryQ,哈希表(hash tableQ,有键列表Qkeyed listQ,或者关联数l?Qassociative arrayQ?
值的有序列表QAn ordered list of valuesQ。在大部分语a中,它被理解为数l(arrayQ?
q些都是常见的数据结构。事实上大部分现代计机语言都以某种形式支持它们。这使得一U数据格式在同样Zq些l构的编E语a之间交换成ؓ(f)可能?/p>
1.对简单数据类型的encoding和decoding:
json.dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=None, separators=None, encoding="utf-8", default=None, sort_keys=False, **kw)
 

        print json.dumps(['foo',{'bar':('baz',None,1.0,2)}])
        
print json.dumps("\"foo\bar")
        print json.dumps(u'\u1234')
        
print json.dumps('\\')
        
print json.dumps({"c":0,"b":0,"a":0},sort_keys=True)

输出Q?br />
["foo", {"bar": ["baz", null, 1.0, 2]}]
"\"foo\bar"
"
\u1234"
"\\"
{
"a": 0, "b": 0, "c": 0}
   compact encoding:
#json主要是作ZU数据通信的格式存在的Q而网l通信是很在乎数据的大的Q无用的I格?x)占据很多通信带宽Q所以适当时候也要对数据q行压羃。separator参数可以起到q样的作用,该参C递是一个元l,包含分割对象的字W串?/span>
print json.dumps([1,2,3,{'4':5,'6':7}],separators=(',',':'))
#indent参数是羃q的意思,它可以得数据存储的格式变得更加优雅?/span>
print json.dumps([1,2,3,{'4':5,'6':7}],separators=(',',':'),indent = 4)
2.decoding JSON
json.load(fp[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]])
print json.loads('["foo",{"bar":["baz",null,1.0,2]}]')
print json.loads('"\\"foo\\bar"')
输出Q?br />
[u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
"foar
3.Ҏ(gu)JSON对象的解?
def as_complex(dct):
if '__complex__' in dct:
return complex(dct['real'],dct['imag'])
return dct

print json.loads('{"__complex__":true,"real":1,"imag":2}',object_hook=as_complex)
输出Q?br />
(1+2j)
 

参见Q?a >http://docs.python.org/2/library/json.html


SunRise_at 2013-01-17 16:28 发表评论
]]>
解决UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-3问题http://m.shnenglu.com/sunrise/archive/2013/01/17/197338.htmlSunRise_atSunRise_atThu, 17 Jan 2013 05:45:00 GMThttp://m.shnenglu.com/sunrise/archive/2013/01/17/197338.htmlhttp://m.shnenglu.com/sunrise/comments/197338.htmlhttp://m.shnenglu.com/sunrise/archive/2013/01/17/197338.html#Feedback0http://m.shnenglu.com/sunrise/comments/commentRss/197338.htmlhttp://m.shnenglu.com/sunrise/services/trackbacks/197338.html在文件的前两行加入:(x)

import os,sys

reload(sys)
sys.setdefaultencoding(
"utf-8")


 



SunRise_at 2013-01-17 13:45 发表评论
]]>
޾Ʒþþwww| ձƷþþþĻ8| ŷսպ91ۺһþþ | þþþ| һþþ| þѾƷav | þavרavһ| þþþó˾ƷĻ| þþƷһ| պŷۺϾþӰԺDs| պһþ | þþ뾫Ʒպ˳| ĻþþƷ1| þ99þ99СݾƷӿ| þҹҹ³³ƬӰ | ۿþ| 99þþƷҹһ| ҹӰԺþþƷѿһ | ƷžžþƵ | ĻۺϾþò| 99Ʒþ| 7777Ʒþþô߽ | þ99Ʒ| ĻþòҰav| þþƷ7777| ŷ˾þƬ| þۺ༤| þۺ϶| 91þþƷ91ɫҲ| 91Ʒþþþþ| þAV| 뾫ƷþþӰ| ޾Ʒþþþȥq| þˬˬƬAV| þˬˬAVƬ| þùһ| þۺϾþþ| þþƷ| þøԴƷ999| þˬ˰| ݺɫþþһ |