用C自撸apache简易模块,搭建图片处理服务器。
写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简易模块,搭建图片处理服务器。的更多相关文章
- 基于koa模块和socket.io模块搭建的node服务器实现通过jwt 验证来渲染列表、私聊、群聊功能
1. 具体代码在需要的下载 https://gitee.com/zyqwasd/socket 效果: 2. package.json文件 1. 下载基本的模块 修改了start 脚本 nodemo ...
- Nginx 搭建图片缓存服务器-转
文章:https://waver.me/2019/04/11/Nginx-Cache-Server/ 参考: Nginx 配置详解Nginx 简易教程Nginx 配置总结
- Erlang/Elixir: 使用 OpenCV, Python 搭建图片缩略图服务器
这篇文章是在OSX上测试和运行的的, Ubuntu下的安装和配置请移步到这里 应用程序进程树, 默认 Poolboy 中初始化10个用于处理图片的 Python 工作进程(Worker) 首先安装Op ...
- 开启Apache mod_rewrite模块(解决404 Not Found)
网站搭建完成了,进入登录界面就是访问不了. 原因大概是没有开启Apache mod_rewrite模块,或者没有配置完全. 步骤1: 启用mod_rewrite模块 在conf目录的httpd.con ...
- 实战:使用SVN+apache搭建一个版本控制服务器
今天讲的内容: 实战:使用SVN+apache搭建一个版本控制服务器 每天: 10:00 晚上:21:00 服务端:xuegod63.cn IP:192.168.10.63 服务概述: SVN(s ...
- Struts2+Spring+Hibernate整合开发(Maven多模块搭建)
Struts2+Spring+Hibernate整合开发(Maven多模块搭建) 0.项目结构 Struts2:web层 Spring:对象的容器 Hibernate:数据库持久化操作 1.父模块导入 ...
- Apache环境下搭建KodExplorer网盘
Apache环境下搭建KodExplorer网盘 环境说明: 系统版本 CentOS 6.9 x86_64 软件版本 yum安装httpd和php kodexplorer4.25 1 ...
- linux+apache+mod_python+wechat_sdk搭建微信公共账号服务器
linux+apache+mod_python+wechat_sdk搭建微信公共账号服务器 转载请注明本文原作者:FignerLiu PRE 最近尝试了下使用python搭建微信公共账号服务器,实现了 ...
- 【青橙商城-管理后台开发】3. web模块搭建
[青橙商城-管理后台开发]3. web模块搭建 1.创建qingcheng_web_manager模块 pom.xml <?xml version="1.0" encodin ...
随机推荐
- SpringBoot mybatis配置
首先pom.xml <!-- mybatis 配置 --> <dependency> <groupId>org.mybatis.spring.boot</gr ...
- Confluence 6 安装指南
在你开始之前 在你开始安装 Confluence 之前,请确定你的安装环境满足 最小系统安装要求和支持的平台. 如果你计划将你的 Confluence 运行到虚拟环境下,请参考 Running Con ...
- python学习(六)
- openLDAP安装时无法操作根节点数据,提示的是This base cannot be created with PLA.
1.无法操作根节点数据,提示的是This base cannot be created with PLA. 解决办法 1)添加一个base.ldif文件,里面的dc和配置文件里的保持一致即可 dn: ...
- 版本管理工具Git(3)VS2013下如何使用git
Git系列导航 版本管理工具Git(1)带你认识git 版本管理工具Git(2)git的安装及使用 版本管理工具Git(3)VS下如何使用git VS下创建项目 vs中新建项目MyGitTest201 ...
- Saiku登录源码追踪.(十三)
Saiku登录源码追踪呀~ >>首先我们需要debug跟踪saiku登录执行的源码信息 saiku源码的debug方式上一篇博客已有说明,这里简单介绍一下 在saiku启动脚本中添加如下命 ...
- MyEclipse中点击部署项目无响应(Deploy MyEclipse J2EE Project to Server)
大部分情况下,只要找到当前的工作空间,删除其中一个文件就可以. 这个文件在Myeclipse工作.metadata\.plugins\org.eclipse.core.runtime\.setting ...
- c++ 生成dll文件并调用-转
.h(头文件) .lib(库文件) .dll(动态链接库文件) 之间的关系和作用的区分 .h头文件是编译时必须的,lib是链接时需要的,dll是运行时需要的. 附加依赖项的是.lib不是.dll, ...
- 2019-04-10-day029-粘包处理
内容回顾 osi五层协议 不是真实存在的,只是抽象出来的模型 应用层 传输层 TCP/UDP TCP :全双工,可靠的,面向连接的,速度慢,对数据大小没有限制 建立连接 :三次握手 SYN ACK 断 ...
- What is the CocoaUI ?
http://www.cocoaui.com/en https://github.com/ideawu/cocoaui 传统的 iOS 应用由于苹果自身的技术所限, 无法实现丰富的 UI 换皮肤(主题 ...