樹心幽徑

« 20181120將上下左右四塊圖磚合併在一起的工具程式(mtile.c) | Main | 20181124將六塊圖磚合併在一起的工具程式(mtile6b.c) »

20181120將上中下左右二欄六列計6塊圖磚合併在一起的工具程式(mtile6.c)
2018/11/20,23:37

(1)編譯:

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/lake$ g++  `Magick++-config --cxxflags --cppflags` -I/usr/local/include/ImageMagick-7  mtile6.c `Magick++-config --ldflags --libs`  -L/usr/local/zlib/lib -lz   -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic -lm -o mtile6

(2)執行
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/lake$ ./mtile6 312x2689-4x3-cw1.png 312x2686-4x3-cw2.png 312x2683-4x3-cw3.png 312x2680-4x3-cw4.png 312x2677-4x3-cw5.png 312x2674-4x3-cw6.png

使用六個來源圖檔
[1:左上312x2689-4x3-cw1.png][4:右上312x2680-4x3-cw4.png]
[2:左中312x2686-4x3-cw2.png][5:右中312x2677-4x3-cw5.png]
[3:左下312x2683-4x3-cw3.png][6:右下312x2674-4x3-cw6.png]

左右上中下各三計6個原始圖寬高皆為 width=1266 height=951
合併6圖後的寬高為 width=2532 height=2853
輸出合併後的圖檔 mtile6.jpg 成功!

(3)程式碼 http://oldwww.kmvs.km.edu.tw/lf/index.php?op=ViewResource&blogId=70&resource=mtile6.c

treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/lake$ cat mtile6.c
//g++  `Magick++-config --cxxflags --cppflags` -I/usr/local/include/ImageMagick-7  mtile6.c `Magick++-config --ldflags --libs`  -L/usr/local/zlib/lib -lz   -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic -lm -o mtile
// https://people.cs.clemson.edu/~dhouse/courses/405/notes/Magick++_tutorial.pdf
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <Magick++.h>

using namespace Magick;
void mtile6(char *fname1,char *fname2,char *fname3,char *fname4,char *fname5, char *fname6){
Image im1(fname1);
Image im2(fname2);
Image im3(fname3);
Image im4(fname4);
Image im5(fname5);
Image im6(fname6);
Geometry size =  im1.size();
double rw=2;
double rh=3;
Image im0(Magick::Geometry(size.width()*rw,size.height()*rh),"white");
//Image blank_image( Geometry(640, 480), Color(MaxRGB, MaxRGB, MaxRGB, 0));
int w=size.width();
int h=size.height();
printf("左右上中下各三計6個原始圖寬高皆為 width=%d height=%d\n",(int)size.width(),(int)size.height());
printf("合併6圖後的寬高為 width=%.0f height=%.0f\n",size.width()*rw,size.height()*rh);
im0.composite(im1, 0, 0, OverCompositeOp);
im0.composite(im2, 0, h-1, OverCompositeOp);
im0.composite(im3, 0, h+h-1, OverCompositeOp);
im0.composite(im4, w-1, 0, OverCompositeOp);
im0.composite(im5, w-1, h-1, OverCompositeOp);
im0.composite(im6, w-1, h+h-1, OverCompositeOp);
im0.write("mtile6.jpg");
printf("輸出合併後的圖檔 mtile6.jpg 成功!\n");
}

int main(int argc, char *argv[])
{
if (argc!=7) {
    printf("2欄3列圖磚合併程式的語法 ./mtile6 1.png 2.png 3.png 4.png 5.png 6.png\n");
    printf("輸出併圖結果檔為mtile6.jpg\n");
    exit(-1);
    }
printf("使用六個來源圖檔\n[1:左上%20s][4:右上%20s]\n[2:左中%20s][5:右中%20s]\n[3:左下%20s][6:右下%20s]",argv[1],argv[4],argv[2],argv[5],argv[3],argv[6]);
mtile6(argv[1],argv[2],argv[3],argv[4],argv[5],argv[6]);
}
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/lake$

 

迴響

 
Accessible and Valid XHTML 1.0 Strict and CSS Powered by LifeType