写C是个撸sir

/*
** mod_acthumb.c -- Apache sample acthumb module
** [Autogenerated via ``apxs -n acthumb -g'']
**
** To play with this sample module first compile it into a
** DSO file and install it into Apache's modules directory
** by running:
**
** $ apxs -c -i mod_acthumb.c
**
** Then activate it in Apache's httpd.conf file for instance
** for the URL /acthumb in as follows:
**
** # httpd.conf
** LoadModule acthumb_module modules/mod_acthumb.so
** <Location /acthumb>
** SetHandler acthumb
** </Location>
**
** Then after restarting Apache via
**
** $ apachectl restart
**
** you immediately can request the URL /acthumb and watch for the
** output of this module. This can be achieved for instance via:
**
** $ lynx -mime_header http://localhost/acthumb
**
** The output should be similar to the following one:
**
** HTTP/1.1 200 OK
** Date: Tue, 31 Mar 1998 14:42:22 GMT
** Server: Apache/1.3.4 (Unix)
** Connection: close
** Content-Type: text/html
**
** The sample page from mod_acthumb.c
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "httpd.h"
#include "http_config.h"
#include "http_protocol.h"
#include "ap_config.h"
#include "wand/MagickWand.h"
/* The sample content handler */
static int acthumb_handler(request_rec *r)
{
if (strcmp(r->handler, "application/acjpg")) {
return DECLINED;
}
r->content_type = "image/jpeg";
if (!r->header_only){
char src[300];
char dest[300];
char generatepic[300];
memset(dest, '\0', sizeof(dest));
strcpy(src,r->filename); //1.jpg.acjpg
strncpy(dest, src, strlen(src)-6); //.acjpg six letters 1.jpg
char *widths = strtok(r->args,"@"); //800
char *heights = strtok(NULL,"@"); //700
int width=atoi(widths);
int height = atoi(heights);
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)){ strncpy(generatepic, dest, strlen(src)-10); //10 .jpg.acjpg fetch 1
char *fileprefix = strtok(dest,".");
char *filesuffix = strtok(NULL,"."); char *POSFILETYPE[]={"jpg","png","gif","jpeg"};
int i;
int hasfiletype=0;
for( i = 0; i < 4; i=i+1){
if(strcmp(POSFILETYPE[i],filesuffix)==0){
hasfiletype = 1;
}
} if(hasfiletype==0){
r->status=HTTP_NOT_FOUND;
ap_send_error_response(r, 0);
} strcat(generatepic,"_");
strcat(generatepic,widths);
strcat(generatepic,"_");
strcat(generatepic,heights);
strcat(generatepic,".");
strcat(generatepic,filesuffix);
strcat(dest,".");
strcat(dest,filesuffix); if((access(generatepic,F_OK))==-1){
MagickBooleanType status;
MagickWand *magick_wand;
MagickWandGenesis();
magick_wand=NewMagickWand();
status=MagickReadImage(magick_wand,dest);
//while (MagickNextImage(magick_wand) != MagickFalse)
MagickResizeImage(magick_wand,width,height,LanczosFilter,1); status=MagickWriteImages(magick_wand,generatepic,MagickTrue); magick_wand=DestroyMagickWand(magick_wand);
MagickWandTerminus();
} apr_file_t *file;
apr_size_t sent;
apr_finfo_t file_info;
apr_status_t rc; apr_stat(&file_info, generatepic, APR_FINFO_MIN, r->pool); rc = apr_file_open(&file, generatepic, APR_READ, APR_OS_DEFAULT,
r->pool); if (rc == APR_SUCCESS) {
ap_send_fd(file, r, 0, (apr_size_t)file_info.size, &sent);
apr_file_close(file);
}
else {
ap_rputs(generatepic,r);
}
}else{
r->status=HTTP_NOT_FOUND;
ap_send_error_response(r, 0);
}
}
return OK;
} static void acthumb_register_hooks(apr_pool_t *p)
{
ap_hook_handler(acthumb_handler, NULL, NULL, APR_HOOK_MIDDLE);
} /* Dispatch list for API hooks */
module AP_MODULE_DECLARE_DATA acthumb_module = {
STANDARD20_MODULE_STUFF,
NULL, /* create per-dir config structures */
NULL, /* merge per-dir config structures */
NULL, /* create per-server config structures */
NULL, /* merge per-server config structures */
NULL, /* table of config file commands */
acthumb_register_hooks /* register hooks */
};

用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. 『Python』VS2015编译源码注意事项

    一.2.5.6版本源码编译 解压 Python-2.5.6.tgz 进入 Pcbuild8 文件夹,使用 vs 2013 打开 pybuild.sln (vs 解决方案),进入 vs2015IDE 环 ...

  2. koa和express对比

    不同: 1.启动方式不同 koa采用了new Koa()的方式,而express采用传统的函数形式 2.中间件形式二者不一样,这是由二者处理中间件的逻辑差异导致的,实际上这也是二者最根本的差别 3.k ...

  3. Hexo-使用

    hexo 写新文章 创建新的文章 ``` bash $ hexo new "Hexo-使用" ``` 生成md文件 ``` bash $ hexo generate ``` 写文章 ...

  4. js对象的深拷贝

    关于对象的深拷贝一直是大家津津乐道一个话题,本骚年通过研究(yuedu)发现还是很easy的. 首推的方法简单有效,JSON.stringfy()和JSON.parse()即可搞定.但是这种简单粗暴的 ...

  5. Chained Exceptions in Java

    1. Overview In this article, we’ll have a very brief look at what Exception is and go in depth about ...

  6. python -- 约束、异常处理、MD5

    1.类的约束       1.写一个父类,父类中的某个方法要抛出一个异常 NotImplementedError class Base: # 对子类进行了约束,必须重写该方法 def login(se ...

  7. 聚合函数count()

    2018-08-12

  8. javascript中NAN undefined 和null

    null 表示无值,而 undefined 表示一个未声明的变量,或已声明但没有赋值的变量,或一个并不存在的对象属性. NaN 属性是代表非数字值的特殊值.该属性用于指示某个值不是数字.可以把 Num ...

  9. 【Java集合系列二】LinkedList解析

    一.简介 1.LinkedList继承关系 2.LinkedList底层实现 LinkedList使用双向链表存储数据,所以没有默认的容量,也不会有扩容一说.只有两个指针,永远指向链表的两端:firs ...

  10. slick插件一些配置