int KmlRenderer::createIconImage(char *fileName, symbolObj *symbol, symbolStyleObj *symstyle) { pointObj p; int status; imageObj *tmpImg = NULL; tmpImg = agg2CreateImage((int)(symbol->sizex*symstyle->scale), (int)(symbol->sizey*symstyle->scale), aggFormat, NULL); tmpImg->format = aggFormat; if (!aggFormat->vtable) msInitializeRendererVTable(aggFormat); p.x = symbol->sizex * symstyle->scale / 2; p.y = symbol->sizey *symstyle->scale / 2; #ifdef USE_POINT_Z_M p.z = 0.0; #endif status = msDrawMarkerSymbol(map,tmpImg, &p, symstyle->style, 1); if( status != MS_SUCCESS ) return status; return msSaveImage(map, tmpImg, fileName); }
/* {{{ proto int saveWebImage() Writes image to temp directory. Returns image URL. */ PHP_METHOD(imageObj, saveWebImage) { zval *zobj = getThis(); php_image_object *php_image; char *imageFile = NULL; char *imageFilename = NULL; char path[MS_MAXPATHLEN]; char *imageUrlFull = NULL; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters_none() == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); php_image = (php_image_object *) zend_object_store_get_object(zobj TSRMLS_CC); imageFilename = msTmpFilename(php_image->image->format->extension); imageFile = msBuildPath(path, php_image->image->imagepath, imageFilename); if (msSaveImage(NULL, php_image->image, imageFile) != MS_SUCCESS) { mapscript_throw_mapserver_exception("Failed writing image to %s" TSRMLS_CC, imageFile); return; } imageUrlFull = msBuildPath(path, php_image->image->imageurl, imageFilename); msFree(imageFilename); RETURN_STRING(imageUrlFull, 1); }
int main(int argc, char *argv[]) { mapObj *map=NULL; imageObj *img=NULL; if(argc > 1 && strcmp(argv[1], "-v") == 0) { printf("%s\n", msGetVersion()); exit(0); } if( argc < 3 ) { fprintf(stdout,"Syntax: legend [mapfile] [output image]\n" ); exit(0); } map = msLoadMap(argv[1], NULL); if(!map) { msWriteError(stderr); exit(0); } img = msDrawLegend(map, MS_FALSE); if(!img) { msWriteError(stderr); exit(0); } msSaveImage(NULL, img, argv[2]); msFreeImage(img); msFreeMap(map); return(MS_TRUE); }
int main(int argc, char *argv[]) { mapObj *map=NULL; imageObj *image = NULL; msSetup(); if(argc > 1 && strcmp(argv[1], "-v") == 0) { printf("%s\n", msGetVersion()); exit(0); } /* ---- check the number of arguments, return syntax if not correct ---- */ if( argc < 3 ) { fprintf(stdout,"Syntax: scalebar [mapfile] [output image]\n" ); exit(1); } map = msLoadMap(argv[1], NULL); if(!map) { msWriteError(stderr); exit(1); } image = msDrawScalebar(map); if(!image) { msWriteError(stderr); exit(1); } msSaveImage(map, image, argv[2]); msFreeImage(image); msFreeMap(map); return(MS_TRUE); }
void msWriteErrorImage(mapObj *map, char *filename, int blank) { imageObj *img; rendererVTableObj *renderer; int font_index = 0; int width=400, height=300; int nMargin =5; int nTextLength = 0; int nUsableWidth = 0; int nMaxCharsPerLine = 0; int nLines = 0; int i = 0; int nStart = 0; int nEnd = 0; int nLength = 0; char **papszLines = NULL; int nXPos = 0; int nYPos = 0; int nWidthTxt = 0; outputFormatObj *format = NULL; char *errormsg = msGetErrorString("; "); fontMetrics *font = NULL; char *imagepath = NULL, *imageurl = NULL; labelStyleObj ls; colorObj labelcolor, labeloutlinecolor, imagecolor, *imagecolorptr=NULL; ls.color = &labelcolor; ls.outlinecolor = &labeloutlinecolor; if (map) { if( map->width > 0 && map->height > 0 ) { width = map->width; height = map->height; } format = map->outputformat; imagepath = map->web.imagepath; imageurl = map->web.imageurl; } /* Default to GIF if no suitable GD output format set */ if (format == NULL || !MS_RENDERER_PLUGIN(format) || !format->vtable->supports_bitmap_fonts) format = msCreateDefaultOutputFormat( NULL, "GD/PC256", "gif" ); if(!format->transparent) { if(map && MS_VALID_COLOR(map->imagecolor)) { imagecolorptr = &map->imagecolor; } else { MS_INIT_COLOR(imagecolor,255,255,255,255); imagecolorptr = &imagecolor; } } img = msImageCreate(width,height,format,imagepath,imageurl,MS_DEFAULT_RESOLUTION,MS_DEFAULT_RESOLUTION,imagecolorptr); renderer = MS_IMAGE_RENDERER(img); for(i=0; i<5; i++) { /* use the first font we find */ if((font = renderer->bitmapFontMetrics[font_index]) != NULL) { ls.size = i; MS_INIT_COLOR(*ls.color,0,0,0,255); MS_INIT_COLOR(*ls.outlinecolor,255,255,255,255); break; } } /* if no font found we can't do much. this shouldn't happen */ if(font) { nTextLength = strlen(errormsg); nWidthTxt = nTextLength * font->charWidth; nUsableWidth = width - (nMargin*2); /* Check to see if it all fits on one line. If not, split the text on several lines. */ if(!blank) { if (nWidthTxt > nUsableWidth) { nMaxCharsPerLine = nUsableWidth/font->charWidth; nLines = (int) ceil ((double)nTextLength / (double)nMaxCharsPerLine); if (nLines > 0) { papszLines = (char **)malloc(nLines*sizeof(char *)); for (i=0; i<nLines; i++) { papszLines[i] = (char *)malloc((nMaxCharsPerLine+1)*sizeof(char)); papszLines[i][0] = '\0'; } } for (i=0; i<nLines; i++) { nStart = i*nMaxCharsPerLine; nEnd = nStart + nMaxCharsPerLine; if (nStart < nTextLength) { if (nEnd > nTextLength) nEnd = nTextLength; nLength = nEnd-nStart; strncpy(papszLines[i], errormsg+nStart, nLength); papszLines[i][nLength] = '\0'; } } } else { nLines = 1; papszLines = (char **)malloc(nLines*sizeof(char *)); papszLines[0] = msStrdup(errormsg); } for (i=0; i<nLines; i++) { nYPos = (font->charHeight) * ((i*2) +1); nXPos = font->charWidth;; renderer->renderBitmapGlyphs(img, nXPos, nYPos, &ls, papszLines[i]); } if (papszLines) { for (i=0; i<nLines; i++) { free(papszLines[i]); } free(papszLines); } } } /* actually write the image */ if(!filename) { msIO_setHeader("Content-type","%s", MS_IMAGE_MIME_TYPE(format)); msIO_sendHeaders(); } msSaveImage(NULL,img,filename); msFreeImage(img); if (format->refcount == 0) msFreeOutputFormat(format); msFree(errormsg); }
PHP_METHOD(imageObj, saveImage) { zval *zobj = getThis(); zval *zmap = NULL; char *filename = NULL; long filename_len = 0; php_image_object *php_image; php_map_object *php_map; int status = MS_SUCCESS; /* stdout specific vars */ int size=0; void *iptr=NULL; PHP_MAPSCRIPT_ERROR_HANDLING(TRUE); if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO", &filename, &filename_len, &zmap, mapscript_ce_map) == FAILURE) { PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); return; } PHP_MAPSCRIPT_RESTORE_ERRORS(TRUE); php_image = (php_image_object *) zend_object_store_get_object(zobj TSRMLS_CC); if (zmap) php_map = (php_map_object *) zend_object_store_get_object(zmap TSRMLS_CC); if(filename_len > 0) { if ((status = msSaveImage((zmap ? php_map->map:NULL), php_image->image, filename) != MS_SUCCESS)) { mapscript_throw_mapserver_exception("Failed writing image to %s" TSRMLS_CC, filename); return; } RETURN_LONG(status); } /* no filename - read stdout */ /* if there is no output buffer active, set the header */ //handle changes in PHP 5.4.x #if PHP_VERSION_ID < 50399 if (OG(ob_nesting_level)<=0) { php_header(TSRMLS_C); } #else if (php_output_get_level(TSRMLS_C)<=0) { php_header(TSRMLS_C); } #endif if (MS_RENDERER_PLUGIN(php_image->image->format)) { iptr = (void *)msSaveImageBuffer(php_image->image, &size, php_image->image->format); } else if (php_image->image->format->name && (strcasecmp(php_image->image->format->name, "imagemap")==0)) { iptr = php_image->image->img.imagemap; size = strlen(php_image->image->img.imagemap); } if (size == 0) { mapscript_throw_mapserver_exception("Failed writing image to stdout" TSRMLS_CC); return; } else { php_write(iptr, size TSRMLS_CC); status = MS_SUCCESS; /* status = size; why should we return the size ?? */ msFree(iptr); } RETURN_LONG(status); }
int main(int argc, char *argv[]) { int i,j,k; mapObj *map=NULL; imageObj *image = NULL; char **layers=NULL; int num_layers=0; int layer_found=0; char *outfile=NULL; /* no -o sends image to STDOUT */ int iterations = 1; int draws = 0; for(i=1;i<argc;i++) { if (strcmp(argv[i],"-c") == 0) { /* user specified number of draws */ iterations = atoi(argv[i+1]); printf("We will draw %d times...\n", iterations); continue; } if(strcmp(argv[i], "-all_debug") == 0 && i < argc-1 ) /* global debug */ { int debug_level = atoi(argv[++i]); msSetGlobalDebugLevel(debug_level); /* Send output to stderr by default */ if (msGetErrorFile() == NULL) msSetErrorFile("stderr", NULL); continue; } } for(draws=0; draws<iterations; draws++) { struct mstimeval requeststarttime, requestendtime; if(msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_TUNING) msGettimeofday(&requeststarttime, NULL); if(argc > 1 && strcmp(argv[1], "-v") == 0) { printf("%s\n", msGetVersion()); exit(0); } /* ---- check the number of arguments, return syntax if not correct ---- */ if( argc < 3 ) { fprintf(stdout, "\nPurpose: convert a mapfile to an image\n\n"); fprintf(stdout, "Syntax: shp2img -m mapfile [-o image] [-e minx miny maxx maxy] [-s sizex sizey]\n" " [-l \"layer1 [layers2...]\"] [-i format]\n" " [-all_debug n] [-map_debug n] [-layer_debug n] [-p n] [-c n] [-d layername datavalue]\n"); fprintf(stdout," -m mapfile: Map file to operate on - required\n" ); fprintf(stdout," -i format: Override the IMAGETYPE value to pick output format\n" ); fprintf(stdout," -o image: output filename (stdout if not provided)\n"); fprintf(stdout," -e minx miny maxx maxy: extents to render\n"); fprintf(stdout," -s sizex sizey: output image size\n"); fprintf(stdout," -l layers: layers / groups to enable - make sure they are quoted and space seperated if more than one listed\n" ); fprintf(stdout," -all_debug n: Set debug level for map and all layers\n" ); fprintf(stdout," -map_debug n: Set map debug level\n" ); fprintf(stdout," -layer_debug layer_name n: Set layer debug level\n" ); fprintf(stdout," -c n: draw map n number of times\n" ); fprintf(stdout," -p n: pause for n seconds after reading the map\n" ); fprintf(stdout," -d layername datavalue: change DATA value for layer\n" ); exit(0); } if ( msSetup() != MS_SUCCESS ) { msWriteError(stderr); exit(1); } /* Use MS_ERRORFILE and MS_DEBUGLEVEL env vars if set */ if ( msDebugInitFromEnv() != MS_SUCCESS ) { msWriteError(stderr); msCleanup(0); exit(1); } for(i=1;i<argc;i++) { /* Step though the user arguments, 1st to find map file */ if(strcmp(argv[i],"-m") == 0) { map = msLoadMap(argv[i+1], NULL); if(!map) { msWriteError(stderr); msCleanup(0); exit(1); } msApplyDefaultSubstitutions(map); } } if(!map) { fprintf(stderr, "Mapfile (-m) option not specified.\n"); msCleanup(0); exit(1); } for(i=1;i<argc;i++) { /* Step though the user arguments */ if(strcmp(argv[i],"-m") == 0) { /* skip it */ i+=1; } if(strcmp(argv[i],"-p") == 0) { int pause_length = atoi(argv[i+1]); time_t start_time = time(NULL); printf( "Start pause of %d seconds.\n", pause_length ); while( time(NULL) < start_time + pause_length ) {} printf( "Done pause.\n" ); i+=1; } if(strcmp(argv[i],"-o") == 0) { /* load the output image filename */ outfile = argv[i+1]; i+=1; } if(strcmp(argv[i],"-i") == 0) { outputFormatObj *format; format = msSelectOutputFormat( map, argv[i+1] ); if( format == NULL ) printf( "No such OUTPUTFORMAT as %s.\n", argv[i+1] ); else { msFree( (char *) map->imagetype ); map->imagetype = msStrdup( argv[i+1] ); msApplyOutputFormat( &(map->outputformat), format, map->transparent, map->interlace, map->imagequality ); } i+=1; } if(strcmp(argv[i],"-d") == 0) { /* swap layer data */ for(j=0; j<map->numlayers; j++) { if(strcmp(GET_LAYER(map, j)->name, argv[i+1]) == 0) { free(GET_LAYER(map, j)->data); GET_LAYER(map, j)->data = msStrdup(argv[i+2]); break; } } i+=2; } if(strcmp(argv[i], "-all_debug") == 0 && i < argc-1 ) /* global debug */ { int debug_level = atoi(argv[++i]); /* msSetGlobalDebugLevel() already called. Just need to force debug * level in map and all layers */ map->debug = debug_level; for(j=0; j<map->numlayers; j++) { GET_LAYER(map, j)->debug = debug_level; } } if(strcmp(argv[i], "-map_debug") == 0 && i < argc-1 ) /* debug */ { map->debug = atoi(argv[++i]); /* Send output to stderr by default */ if (msGetErrorFile() == NULL) msSetErrorFile("stderr", NULL); } if(strcmp(argv[i], "-layer_debug") == 0 && i < argc-1 ) /* debug */ { const char *layer_name = argv[++i]; int debug_level = atoi(argv[++i]); int got_layer = 0; for(j=0; j<map->numlayers; j++) { if(strcmp(GET_LAYER(map, j)->name,layer_name) == 0 ) { GET_LAYER(map, j)->debug = debug_level; got_layer = 1; } } if( !got_layer ) fprintf( stderr, " Did not find layer '%s' from -layer_debug switch.\n", layer_name ); /* Send output to stderr by default */ if (msGetErrorFile() == NULL) msSetErrorFile("stderr", NULL); } if(strcmp(argv[i],"-e") == 0) { /* change extent */ if( argc <= i+4 ) { fprintf( stderr, "Argument -e needs 4 space separated numbers as argument.\n" ); msCleanup(0); exit(1); } map->extent.minx = atof(argv[i+1]); map->extent.miny = atof(argv[i+2]); map->extent.maxx = atof(argv[i+3]); map->extent.maxy = atof(argv[i+4]); i+=4; } if (strcmp(argv[i], "-s") == 0) { msMapSetSize(map, atoi(argv[i+1]), atoi(argv[i+2])); i+=2; } if(strcmp(argv[i],"-l") == 0) { /* load layer list */ layers = msStringSplit(argv[i+1], ' ', &(num_layers)); for(j=0; j<num_layers; j++) { /* loop over -l */ layer_found=0; for(k=0; k<map->numlayers; k++) { if((GET_LAYER(map, k)->name && strcasecmp(GET_LAYER(map, k)->name, layers[j]) == 0) || (GET_LAYER(map, k)->group && strcasecmp(GET_LAYER(map, k)->group, layers[j]) == 0)) { layer_found = 1; break; } } if (layer_found==0) { fprintf(stderr, "Layer (-l) \"%s\" not found\n", layers[j]); msCleanup(0); exit(1); } } for(j=0; j<map->numlayers; j++) { if(GET_LAYER(map, j)->status == MS_DEFAULT) continue; else { GET_LAYER(map, j)->status = MS_OFF; for(k=0; k<num_layers; k++) { if((GET_LAYER(map, j)->name && strcasecmp(GET_LAYER(map, j)->name, layers[k]) == 0) || (GET_LAYER(map, j)->group && strcasecmp(GET_LAYER(map, j)->group, layers[k]) == 0)) { GET_LAYER(map, j)->status = MS_ON; break; } } } } msFreeCharArray(layers, num_layers); i+=1; } } image = msDrawMap(map, MS_FALSE); if(!image) { msWriteError(stderr); msFreeMap(map); msCleanup(0); exit(1); } if( msSaveImage(map, image, outfile) != MS_SUCCESS ) { msWriteError(stderr); } msFreeImage(image); msFreeMap(map); if(msGetGlobalDebugLevel() >= MS_DEBUGLEVEL_TUNING) { msGettimeofday(&requestendtime, NULL); msDebug("shp2img total time: %.3fs\n", (requestendtime.tv_sec+requestendtime.tv_usec/1.0e6)- (requeststarttime.tv_sec+requeststarttime.tv_usec/1.0e6) ); } msCleanup(0); } /* for(draws=0; draws<iterations; draws++) { */ return(0); } /* ---- END Main Routine ---- */