湖濱散記部落格的樹心幽徑[login][主頁]
443:20181128讀取檔名文字檔產生影像陣列,再以column major合併(mtile6e.c)

(1a)編譯

$ g++  `Magick++-config --cxxflags --cppflags` -I/usr/local/include/ImageMagick-7  mtile6e.c `Magick++-config --ldflags --libs`  -L/usr/local/zlib/lib -lz   -Wall  -export-dynamic -lm -o mtile6e

(1b)輸入檔:fname.txt

$ cat fname.txt
312x2689-4x3-cw1.png
312x2686-4x3-cw2.png
312x2683-4x3-cw3.png
312x2680-4x3-cw4.png
312x2677-4x3-cw5.png
312x2674-4x3-cw6.png

(2) 執行

$ ./mtile6e fname.txt 3 2
fn[0]=312x2689-4x3-cw1.png
fn[1]=312x2686-4x3-cw2.png
fn[2]=312x2683-4x3-cw3.png
fn[3]=312x2680-4x3-cw4.png
fn[4]=312x2677-4x3-cw5.png
fn[5]=312x2674-4x3-cw6.png

 0
 0(0,0) 3(0,1)
 1
 1(1,0) 4(1,1)
 2
 2(2,0) 5(2,1)
輸出六圖合併後的圖檔 mtile6e.jpg 成功!

(3)程式碼 mtile6e.c

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <Magick++.h>

using namespace Magick;
void xtile(char *fn[],int row,int col){
    Image ima[6];
    for(int i=0;i<6;i++){
        ima[i]=Image(fn[i]);
        printf("fn[%d]=%s\n",i,fn[i]);
        }
    Geometry size =  ima[0].size();
    int w=size.width();
    int h=size.height();
    Image im(Magick::Geometry(w*col,h*row),"white");
    for(int r=0;r<row;r++){
        printf("\n %d\n",r);
        for(int c=0;c<col;c++){
            int p=c*row+r;
            if(p<6){
                im.composite(ima[p], c*w, r*h, OverCompositeOp);
            }
            printf(" %d(%d,%d)",p,r,c);
        }
    }
    printf("\n");
    im.write("mtile6e.jpg");
    printf("輸出六圖合併後的圖檔 mtile6e.jpg 成功!\n");
}


int main(int argc, char *argv[]){
    if (argc!=4) {
        printf("圖磚合併程式的語法 ./mtile6e fname.txt row col\n");
        printf("輸出併圖結果檔為mtile6e.jpg\n");
        exit(-1);
    }
    int row=atoi(argv[2]);
    int col=atoi(argv[3]);

    char *fn[6];
    char st[6][80];

    FILE *fp;
      fp = fopen(argv[1] , "r");  //argv[1] use for img filename
      if(fp == NULL) {
          perror("Error opening file");
          return(-1);
       }
    for(int i=0;i<6;i++){
        fgets(st[i],80,fp);
        st[i][strlen(st[i])-1]=0;
        fn[i]=st[i];
    }
        fclose(fp);
    xtile(fn,row,col);
}




select id,article_id,topic,text from lt_articles_text where article_id =443; ok. update lt_articles set num_reads=num_reads +1 where id=443; ok.