用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 ...
随机推荐
- Java集合框架源码分析(2)LinkedList
链表(LinkedList) 数组(array)和数组列表(ArrayList)都有一个重大的缺陷: 从数组的中间位置删除一个元素要付出很大的代价,因为数组中在被删除元素之后的所有元素都要向数组的前端 ...
- php 中swoole安装
1.下载扩展包: 网址:http://pecl.php.net/ 中(http://pecl.php.net/get/swoole-4.3.1.tgz) 2.解压安装包. 3.进入解压好的安装包. 4 ...
- yii框架通过http协议获取地址栏中的内容
//创建一个控制器 <?php namespace frontend\controllers; use frontend\models\Zhuce; use Yii; use yii\web\C ...
- IDEA-------破解方法
① 到这个地方下载 IntelliJ IDEA 注册码:http://idea.lanyus.com/ 就是这个jar包:JetbrainsCrack-2.6.10-release-enc.jar ...
- django中邮件、日志的配置
邮件的发送及配置 # 配置邮件 EMAIL_USE_SSL = True EMAIL_HOST = 'smtp.qq.com' # 如果是 163 改成 smtp.163.com EMAIL_PORT ...
- QSplineSeries QChartView绘制曲线
参考资料: https://www.qtdebug.com/qtbook-paint-smooth-curve-qchart/ https://blog.csdn.net/liang19890820/ ...
- python 实现树结构
简述: 研究 MCTS 过程中, 需要用到树结构. baidu google 了一番, 找不到自己能满足自己的库或代码参考,只好再造个轮子出来 我造的树用来下五子棋 和 围棋用的, 有其它不 ...
- angularjs checkbox
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- sticky footer
html: <div class="detail"> <div class="detail-wrapper"> <div clas ...
- Linux中的15个基本'ls'命令示例
ls命令是Linux中最常用的命令之一.我相信ls命令是你进入Linux 系统命令提示符时的首选命令. 我们每天都在使用ls命令,甚至常常意识不到这一点,也从没有使用所有可用的ls选项.在这篇文章,我 ...