写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. android -------- Retrofit + RxJava2.0 + Kotlin + MVP 开发的 WanAndroid 项目

    简介 wanandroid项目基于 Retrofit + RxJava2.0 + Kotlin + MVP 用到的依赖 implementation 'io.reactivex.rxjava2:rxj ...

  2. Git中修复bug

    问题描述:提交的远程分支中有一个小bug需要修复: 首先在本地拉取指定分支的代码: git checkout -b test origin/远程分支 git pull 再从test分支中切一个分支: ...

  3. 使用python来访问Hadoop HDFS存储实现文件的操作

    原文:http://rfyiamcool.blog.51cto.com/1030776/1258292 在调试环境下,咱们用hadoop提供的shell接口测试增加删除查看,但是不利于复杂的逻辑编程 ...

  4. AngelToken:区块链技术的突破

    科技进步,直接捅破了政治.金融.军事领域所有的玩法,让工业革命以来形成的规则变得一钱不值. 而且,当下的最重要的技术趋势——区块链.Token.AngelToken,正在引导我们走向全面的失控和未知. ...

  5. [Codeforces440D]Berland Federalization

    Problem 给你一棵树,最少删掉哪些边,能使得余下的至少有1个大小刚好为k的残树. 1 ≤ k ≤ n ≤ 400 Solution 用f[i][j]表示以i为根有j个节点的最少删边数量 因为此题 ...

  6. mysql数据库基础语句训练题

    ; -- ---------------------------- -- Table structure for course -- ---------------------------- DROP ...

  7. 如何使用 Excel 对象将 DataGridView 数据导出到 Excel

    转载出处:https://code.msdn.microsoft.com/How-to-insert-image-into-93964561 本项目阐述如何使用 Open XML SDK 将图像插入到 ...

  8. mybatis 使用IN 关键字

    mybatis 使用IN 关键字,查询条件如果有多个,拼接成字符串,当做参数传入的时候可能会只查询一条数据,那是因为mybits 将它当做一个字符串来处理了,这时候就需要使用<foreach&g ...

  9. 前端修炼の道 | <div> 标签简介

    <div> 标签是最基本的,同时也是最常用的标签. 该标签是一个双标签,出现在主体区域中,主要作为一个容器标签来使用,在 <div> 标签中可以包含除 <body> ...

  10. 异常处理:try - except 和 try finally。

    异常处理:try-except语句 1)      此处:as reason为可选参数,reason是一个变量. 2)      使用try—except语句时,检测范围内出现错误,不会有红色的报错提 ...