写C是个撸sir

  1. /*
  2. ** mod_acthumb.c -- Apache sample acthumb module
  3. ** [Autogenerated via ``apxs -n acthumb -g'']
  4. **
  5. ** To play with this sample module first compile it into a
  6. ** DSO file and install it into Apache's modules directory
  7. ** by running:
  8. **
  9. ** $ apxs -c -i mod_acthumb.c
  10. **
  11. ** Then activate it in Apache's httpd.conf file for instance
  12. ** for the URL /acthumb in as follows:
  13. **
  14. ** # httpd.conf
  15. ** LoadModule acthumb_module modules/mod_acthumb.so
  16. ** <Location /acthumb>
  17. ** SetHandler acthumb
  18. ** </Location>
  19. **
  20. ** Then after restarting Apache via
  21. **
  22. ** $ apachectl restart
  23. **
  24. ** you immediately can request the URL /acthumb and watch for the
  25. ** output of this module. This can be achieved for instance via:
  26. **
  27. ** $ lynx -mime_header http://localhost/acthumb
  28. **
  29. ** The output should be similar to the following one:
  30. **
  31. ** HTTP/1.1 200 OK
  32. ** Date: Tue, 31 Mar 1998 14:42:22 GMT
  33. ** Server: Apache/1.3.4 (Unix)
  34. ** Connection: close
  35. ** Content-Type: text/html
  36. **
  37. ** The sample page from mod_acthumb.c
  38. */
  39. #include <string.h>
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <unistd.h>
  43. #include "httpd.h"
  44. #include "http_config.h"
  45. #include "http_protocol.h"
  46. #include "ap_config.h"
  47. #include "wand/MagickWand.h"
  48. /* The sample content handler */
  49. static int acthumb_handler(request_rec *r)
  50. {
  51. if (strcmp(r->handler, "application/acjpg")) {
  52. return DECLINED;
  53. }
  54. r->content_type = "image/jpeg";
  55. if (!r->header_only){
  56. char src[300];
  57. char dest[300];
  58. char generatepic[300];
  59. memset(dest, '\0', sizeof(dest));
  60. strcpy(src,r->filename); //1.jpg.acjpg
  61. strncpy(dest, src, strlen(src)-6); //.acjpg six letters 1.jpg
  62. char *widths = strtok(r->args,"@"); //800
  63. char *heights = strtok(NULL,"@"); //700
  64. int width=atoi(widths);
  65. int height = atoi(heights);
  66. if((width==50 && height==50) || (width==100 && height==100) || (width==300 && height==300) || (width==500 && height==500) || (width==640 && height==640) || (width==640 && height > 200)){
  67. strncpy(generatepic, dest, strlen(src)-10); //10 .jpg.acjpg fetch 1
  68. char *fileprefix = strtok(dest,".");
  69. char *filesuffix = strtok(NULL,".");
  70. char *POSFILETYPE[]={"jpg","png","gif","jpeg"};
  71. int i;
  72. int hasfiletype=0;
  73. for( i = 0; i < 4; i=i+1){
  74. if(strcmp(POSFILETYPE[i],filesuffix)==0){
  75. hasfiletype = 1;
  76. }
  77. }
  78. if(hasfiletype==0){
  79. r->status=HTTP_NOT_FOUND;
  80. ap_send_error_response(r, 0);
  81. }
  82. strcat(generatepic,"_");
  83. strcat(generatepic,widths);
  84. strcat(generatepic,"_");
  85. strcat(generatepic,heights);
  86. strcat(generatepic,".");
  87. strcat(generatepic,filesuffix);
  88. strcat(dest,".");
  89. strcat(dest,filesuffix);
  90. if((access(generatepic,F_OK))==-1){
  91. MagickBooleanType status;
  92. MagickWand *magick_wand;
  93. MagickWandGenesis();
  94. magick_wand=NewMagickWand();
  95. status=MagickReadImage(magick_wand,dest);
  96. //while (MagickNextImage(magick_wand) != MagickFalse)
  97. MagickResizeImage(magick_wand,width,height,LanczosFilter,1);
  98. status=MagickWriteImages(magick_wand,generatepic,MagickTrue);
  99. magick_wand=DestroyMagickWand(magick_wand);
  100. MagickWandTerminus();
  101. }
  102. apr_file_t *file;
  103. apr_size_t sent;
  104. apr_finfo_t file_info;
  105. apr_status_t rc;
  106. apr_stat(&file_info, generatepic, APR_FINFO_MIN, r->pool);
  107. rc = apr_file_open(&file, generatepic, APR_READ, APR_OS_DEFAULT,
  108. r->pool);
  109. if (rc == APR_SUCCESS) {
  110. ap_send_fd(file, r, 0, (apr_size_t)file_info.size, &sent);
  111. apr_file_close(file);
  112. }
  113. else {
  114. ap_rputs(generatepic,r);
  115. }
  116. }else{
  117. r->status=HTTP_NOT_FOUND;
  118. ap_send_error_response(r, 0);
  119. }
  120. }
  121. return OK;
  122. }
  123. static void acthumb_register_hooks(apr_pool_t *p)
  124. {
  125. ap_hook_handler(acthumb_handler, NULL, NULL, APR_HOOK_MIDDLE);
  126. }
  127. /* Dispatch list for API hooks */
  128. module AP_MODULE_DECLARE_DATA acthumb_module = {
  129. STANDARD20_MODULE_STUFF,
  130. NULL, /* create per-dir config structures */
  131. NULL, /* merge per-dir config structures */
  132. NULL, /* create per-server config structures */
  133. NULL, /* merge per-server config structures */
  134. NULL, /* table of config file commands */
  135. acthumb_register_hooks /* register hooks */
  136. };

用C自撸apache简易模块,搭建图片处理服务器。的更多相关文章

  1. 基于koa模块和socket.io模块搭建的node服务器实现通过jwt 验证来渲染列表、私聊、群聊功能

    1. 具体代码在需要的下载 https://gitee.com/zyqwasd/socket 效果: 2. package.json文件 1. 下载基本的模块  修改了start 脚本  nodemo ...

  2. Nginx 搭建图片缓存服务器-转

    文章:https://waver.me/2019/04/11/Nginx-Cache-Server/ 参考: Nginx 配置详解Nginx 简易教程Nginx 配置总结

  3. Erlang/Elixir: 使用 OpenCV, Python 搭建图片缩略图服务器

    这篇文章是在OSX上测试和运行的的, Ubuntu下的安装和配置请移步到这里 应用程序进程树, 默认 Poolboy 中初始化10个用于处理图片的 Python 工作进程(Worker) 首先安装Op ...

  4. 开启Apache mod_rewrite模块(解决404 Not Found)

    网站搭建完成了,进入登录界面就是访问不了. 原因大概是没有开启Apache mod_rewrite模块,或者没有配置完全. 步骤1: 启用mod_rewrite模块 在conf目录的httpd.con ...

  5. 实战:使用SVN+apache搭建一个版本控制服务器

    今天讲的内容: 实战:使用SVN+apache搭建一个版本控制服务器 每天: 10:00 晚上:21:00 服务端:xuegod63.cn   IP:192.168.10.63 服务概述: SVN(s ...

  6. Struts2+Spring+Hibernate整合开发(Maven多模块搭建)

    Struts2+Spring+Hibernate整合开发(Maven多模块搭建) 0.项目结构 Struts2:web层 Spring:对象的容器 Hibernate:数据库持久化操作 1.父模块导入 ...

  7. Apache环境下搭建KodExplorer网盘

    Apache环境下搭建KodExplorer网盘 环境说明: 系统版本    CentOS 6.9 x86_64 软件版本    yum安装httpd和php    kodexplorer4.25 1 ...

  8. linux+apache+mod_python+wechat_sdk搭建微信公共账号服务器

    linux+apache+mod_python+wechat_sdk搭建微信公共账号服务器 转载请注明本文原作者:FignerLiu PRE 最近尝试了下使用python搭建微信公共账号服务器,实现了 ...

  9. 【青橙商城-管理后台开发】3. web模块搭建

    [青橙商城-管理后台开发]3. web模块搭建 1.创建qingcheng_web_manager模块 pom.xml <?xml version="1.0" encodin ...

随机推荐

  1. Java集合框架源码分析(2)LinkedList

    链表(LinkedList) 数组(array)和数组列表(ArrayList)都有一个重大的缺陷: 从数组的中间位置删除一个元素要付出很大的代价,因为数组中在被删除元素之后的所有元素都要向数组的前端 ...

  2. php 中swoole安装

    1.下载扩展包: 网址:http://pecl.php.net/ 中(http://pecl.php.net/get/swoole-4.3.1.tgz) 2.解压安装包. 3.进入解压好的安装包. 4 ...

  3. yii框架通过http协议获取地址栏中的内容

    //创建一个控制器 <?php namespace frontend\controllers; use frontend\models\Zhuce; use Yii; use yii\web\C ...

  4. IDEA-------破解方法

    ① 到这个地方下载 IntelliJ IDEA 注册码:http://idea.lanyus.com/  就是这个jar包:JetbrainsCrack-2.6.10-release-enc.jar ...

  5. django中邮件、日志的配置

    邮件的发送及配置 # 配置邮件 EMAIL_USE_SSL = True EMAIL_HOST = 'smtp.qq.com' # 如果是 163 改成 smtp.163.com EMAIL_PORT ...

  6. QSplineSeries QChartView绘制曲线

    参考资料: https://www.qtdebug.com/qtbook-paint-smooth-curve-qchart/ https://blog.csdn.net/liang19890820/ ...

  7. python 实现树结构

    简述: 研究  MCTS 过程中, 需要用到树结构.  baidu  google 了一番, 找不到自己能满足自己的库或代码参考,只好再造个轮子出来 我造的树用来下五子棋 和 围棋用的,   有其它不 ...

  8. angularjs checkbox

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. sticky footer

    html: <div class="detail"> <div class="detail-wrapper"> <div clas ...

  10. Linux中的15个基本'ls'命令示例

    ls命令是Linux中最常用的命令之一.我相信ls命令是你进入Linux 系统命令提示符时的首选命令. 我们每天都在使用ls命令,甚至常常意识不到这一点,也从没有使用所有可用的ls选项.在这篇文章,我 ...