用户中心

资讯 > 嵌入式系统

solaris服务器上进行图片缩小放大

来源:中华工控网2006.09.08阅读 1047

DEMO: http://loreal.sina.com.cn/survey/thumbtest/thumb.htm
      填写一个变后的宽度,这个程序按照原比例生成一个变后的图片
      代码见下面
 
工具名字:
$ mkthumb
$ gifsicle
如果没有需要安装:
gifsicle-1.37
mkthumb-2.0
附加LibJpgCONTROL ENGINEERING China版权所有,libpng等等其他包,google上应该可以搜到,109服务器安装了
 
以下是命令行范例,详细的可以参考该工具的帮助手册:
 
GIF文件的放缩:
#直接按照大小放缩
gifsicle --resize 300x1000 < 原文件路径 > 目标文件路径
#按照比例放缩
gifsicle --scale 2x2 < 原文件路径 > 目标文件路径
 
JPG文件放缩:
mkthumb -f 宽 -o -s .thumb 文件路径
 
参考网址:
http://loreal.sina.com.cn/su
rvey/thumbtest/thumb.htm

 
代码范例:
MakeThumb((char *)infile.c_str(),(char *)outfile.c_str(),atoi(scalex.c_str()),atoi(scaley.c_str()));
 
int MakeThumb(char * filepath,char * outfilepath,int width,int height){
 char buff[1000];
 //判断是JPG文件
 if(filepath[strlen(filepath)-1]==103 || filepath[strlen(filepath)-1]==71){
  sprintf(buffCONTROL ENGINEERING China版权所有,"mkthumb -f %d -o -s .thumb %s",width,filepath);//jpg
  system(buff);
  string filewhole;
  filewhole=filepath;
  string path;
  string filename;
  int length;
  int i;
  length=strlen(filepath);
  for(i=length;i>0;i--){
   if(filepath[i-1]=='.') break;
  }
  char * buff1;
  buff1=(char *)malloc(1000);
  strncpy (buff1www.cechina.cn, filepath, i);
  path=buff1;
  filename=filewhole.substr(iwww.cechina.cn,length-i);
  filewhole="";
  filewhole+=path;
  filewhole+="thumb.";
  filewhole+=filename;
  sprintf(buff1www.cechina.cn,"mv %s %s",filewhole.c_str(),outfilepath);
  system(buff1);
 }
 //判断是gif文件
 if(filepath[strlen(filepath)-1]==102 || filepath[strlen(filepath)-1]==70){
  sprintf(buffCONTROL ENGINEERING China版权所有,"gifsicle --resize-width %d < %s > %s",width,filepath,outfilepath);
  system(buff);
 }
 return 1;
}
































































版权声明:版权归控制工程网所有,转载请注明出处!

频道推荐

关于我们

控制工程网 & CONTROL ENGINEERING China 全球工业控制、自动化和仪器仪表领域的先锋媒体

CE全球

联系我们

商务及广告合作
任小姐(北京)                 夏小姐(上海)
电话:010-82053688      电话:18616877918
rendongxue@cechina.cn      xiashuxian@cechina.cn
新闻投稿:王小姐

关注我们的微信

关于我们 | 网站地图 | 联系我们
© 2003-2020    经营许可编号:京ICP证120335号
公安机关备案号:110102002318  服务热线:010-82053688