int barcode_to_png (char *image_name) { MagickWand *magick_wand; MagickBooleanType status; int width, height, pad, half_pad; /* read a barcode image */ MagickWandGenesis(); magick_wand = NewMagickWand(); MagickSetResolution(magick_wand, 300, 300); status = MagickReadImage(magick_wand, image_name); if (status == MagickFalse) ThrowWandException(magick_wand, 1); /* trim the image, resample it, and pad it by [10% of the long side] per side */ MagickTrimImage(magick_wand, 10); width = MagickGetImageWidth(magick_wand); height = MagickGetImageHeight(magick_wand); pad = determine_padding(width, height); half_pad = round(pad/2); MagickExtentImage(magick_wand, width+pad, height+pad, -half_pad, -half_pad); /* write image (a PNG version and a formatted PS version) */ status=MagickWriteImage(magick_wand, chop_path(image_name, ".png")); if (status == MagickFalse) ThrowWandException(magick_wand, 2); status=MagickWriteImage(magick_wand, chop_path(image_name, ".ps")); if (status == MagickFalse) ThrowWandException(magick_wand, 2); /* clean up */ magick_wand=DestroyMagickWand(magick_wand); MagickWandTerminus(); return 0; }
Object c_Gmagick::t_writeimage(CStrRef filename, bool all_frames) { INSTANCE_METHOD_INJECTION_BUILTIN(Gmagick, Gmagick::writeimage); checkNotEmpty(); const char *c_filename; if (filename.isNull()) { c_filename = MagickGetImageFilename(magick_wand); if (!c_filename) { throwException("No image filename specified", FileOpenFatalError); } } else { c_filename = filename->data(); } int filename_len = strlen(c_filename); if (!filename_len) { throwException("Unable to write the image. Empty filename string provided", FileOpenFatalError); } int result; if (all_frames) { result = MagickWriteImage(magick_wand, c_filename); } else { result = MagickWriteImages(magick_wand, c_filename, MagickTrue); } checkResult(result); return this; }
/** * Helper function to provide a visual interpretation of the accumulator. */ void print_accumulator(char* name) { MagickWand *mw = NULL; PixelWand **pmw = NULL; PixelIterator *imw = NULL; MagickWandGenesis(); unsigned long width, height; width = _circumference; height = _dimensions.semi_diagonal; mw = NewMagickWand(); MagickSetSize(mw, width, height); MagickReadImage(mw, "xc:black"); imw = NewPixelIterator(mw); int y, x; for (y=0; y<height; y++) { pmw = PixelGetNextIteratorRow(imw, &width); for (x=0; x< (long) width; x++) { _CELL_TYPE* cell = &_accumulator[x][height-y-1]; PixelSetRed(pmw[x], 1.0/20.0 * cell->count); } PixelSyncIterator(imw); } MagickWriteImage(mw, name); if(mw) mw = DestroyMagickWand(mw); MagickWandTerminus(); }
int main(int argc, char* argv[]) { MagickWand *mw = NULL; DrawingWand *dw = NULL; PixelWand *fill = NULL; int x,y; MagickWandGenesis(); mw = NewMagickWand(); MagickReadImage(mw,"logo:"); fill = NewPixelWand(); dw = NewDrawingWand(); PixelSetColor(fill,"green"); DrawSetFillColor(dw,fill); for (x=200;x<210;x++) for (y=100;y<110;y++) DrawPoint(dw,x,y); MagickDrawImage(mw,dw); MagickWriteImage(mw,"logo.jpg"); if (dw) dw = DestroyDrawingWand(dw); if (fill) fill = DestroyPixelWand(fill); if (mw) mw = DestroyMagickWand(mw); MagickWandTerminus(); }
int main(int argc,char **argv) { MagickWand *magick_wand_background; MagickWand *magick_wand_foreground; MagickWandGenesis(); magick_wand_background = NewMagickWand(); magick_wand_foreground = NewMagickWand(); MagickReadImage(magick_wand_background, "magick:logo"); MagickReadImage(magick_wand_foreground, "magick:rose"); MagickSetGravity(magick_wand_background, CenterGravity); MagickSetGravity(magick_wand_foreground, CenterGravity); MagickCompositeImage( magick_wand_background, magick_wand_foreground, AtopCompositeOp, 0, 0 ); MagickSetFormat(magick_wand_background, "png"); MagickWriteImage(magick_wand_background, "./output/gravity.png"); MagickWandTerminus(); return 0; }
int main(int argc,char **argv) { char filename[MaxTextExtent]; MagickBooleanType status; MagickWand *canvas; if (argc != 2) { (void) printf ("Usage: %s filename\n",argv[0]); exit(1); } (void) CopyMagickString(filename,argv[1],MaxTextExtent); /* Create canvas image. */ MagickWandGenesis(); canvas=NewMagickWand(); status=MagickSetSize(canvas,596,842); if (status == MagickFalse) ThrowWandException(canvas); status=MagickReadImage(canvas,"xc:white"); if (status == MagickFalse) ThrowWandException(canvas); /* Scribble on image. */ status=ScribbleImage(canvas); if (status == MagickFalse) ThrowWandException(canvas); /* Set pixel depth to 8. */ status=MagickSetImageDepth(canvas,8); if (status == MagickFalse) ThrowWandException(canvas); /* Set output as RLE compressed. */ status=MagickSetImageCompression(canvas,RLECompression); if (status == MagickFalse) ThrowWandException(canvas); /* Save image to file. */ status=MagickWriteImage(canvas,filename); if (status == MagickFalse) ThrowWandException(canvas); canvas=DestroyMagickWand(canvas); MagickWandTerminus(); return(0); }
void main(void) { clock_t begin, end; double time_spent; double imageAspectRatio = 0; double originalWidth; double originalHeight; double masterAspectRatio = 1.77; MagickWand *m_wand = NULL; int width,height; MagickWandGenesis(); m_wand = NewMagickWand(); MagickReadImage(m_wand,"mona-lisa.JPG"); begin = clock(); originalWidth = MagickGetImageWidth(m_wand); originalHeight = MagickGetImageHeight(m_wand); imageAspectRatio = originalWidth/originalHeight; if(imageAspectRatio <= masterAspectRatio) { MagickCropImage(m_wand,originalWidth,(int)(originalWidth/masterAspectRatio),0,(originalHeight-(int)(originalWidth/masterAspectRatio))/2 ); printf("%d X %d ",MagickGetImageWidth(m_wand) , MagickGetImageHeight(m_wand)); } else { MagickCropImage(m_wand,(int)(originalHeight * masterAspectRatio),originalHeight,(originalWidth - (int)(originalHeight * masterAspectRatio))/2,0); } if (originalWidth > 1920) MagickResizeImage(m_wand,1920,1080,LanczosFilter,1); end = clock(); time_spent = (double)(end - begin) / CLOCKS_PER_SEC; printf("Time taken is %f\n",time_spent); // MagickCropImage(m_wand,originalWidth/2,originalHeight/2,0,0); // Set the compression quality to 95 (high quality = low compression) //MagickSetImageCompressionQuality(m_wand,95); /* Write the new image */ MagickWriteImage(m_wand,"master.jpg"); /* Clean up */ if(m_wand)m_wand = DestroyMagickWand(m_wand); MagickWandTerminus();}
int main (int argc, char **argv) { if (argc != 5) { printf ("Usage: %s image_file scheme_file key_file layout_type\n", argv[0]); return (0); } char *ifile_name = argv[1]; char *ofile_name = argv[2]; char *key_name = argv[3]; SM_LayoutType layout_type = (SM_LayoutType)atoi(argv[4]); MagickWandGenesis(); ExceptionInfo *exception = AcquireExceptionInfo(); MagickWand *image = NewMagickWand(); // Read an image. printf("Proceeding file %s\n", ifile_name); MagickReadImage(image, ifile_name); SM_SchemeGenerator *generator = SM_CrossStitchSchemeGenerator_New(); SM_Scheme *scheme_base = SM_SchemeGenerator_GenerateScheme(generator, image); MagickWand *scheme = SM_CrossStitch_Color_Draw(scheme_base, layout_type); scheme_base->cell_info.square->width *= 2; MagickWand *key = SM_CrossStitch_Key_Draw(scheme_base, layout_type); MagickWriteImage(scheme, ofile_name); MagickWriteImage(key, key_name); SM_SchemeGenerator_Delete(generator); SM_Scheme_Delete(scheme_base); DestroyMagickWand(image); DestroyMagickWand(scheme); exception = DestroyExceptionInfo(exception); MagickWandTerminus(); printf("Done!\n"); return (0); }
void save_image(ConvertContext *context) { int result = RESULT_OK; char *error_desc; ExceptionType error_type; // get pixel data if (context->hasAlphaChannel == MagickTrue) { if (MagickImportImagePixels(context->mw, 0, 0, context->imageWidth, context->imageHeight, "ARGB", CharPixel, context->pixels) == MagickFalse) { error_desc = MagickGetException(context->mw, &error_type); asprintf(&context->results.message, "Error exporting pixel data (%s): %s\n",error_desc,context->src_path); error_desc = (char *)MagickRelinquishMemory(error_desc); result += RESULT_ERROR; } } // convert image to PNG if (result == RESULT_OK) { if (MagickSetImageFormat(context->mw,"PNG") == MagickFalse) { error_desc = MagickGetException(context->mw, &error_type); asprintf(&context->results.message,"Error converting image (%s): %s\n",error_desc,context->src_path); error_desc = (char *)MagickRelinquishMemory(error_desc); result += RESULT_ERROR; } } // activate/deactivate alpha channel MagickSetImageAlphaChannel(context->mw, (context->results.alpha_type == ALPHA_TYPE_NONE ? DeactivateAlphaChannel : ActivateAlphaChannel)); // make sure image is saved as RGB and not crunched down to grayscale MagickSetType(context->mw, (context->results.alpha_type == ALPHA_TYPE_NONE ? TrueColorType : TrueColorMatteType)); // save image to disk if (result == RESULT_OK) { if (MagickWriteImage(context->mw, context->dst_path) == MagickFalse) { error_desc = MagickGetException(context->mw, &error_type); asprintf(&context->results.message, "Error saving image (%s): %s\n",error_desc,context->dst_path); error_desc = (char *)MagickRelinquishMemory(error_desc); result += RESULT_ERROR; } } if (result == RESULT_OK && context->options.delete_original != 0) { if (unlink(context->src_path) == -1) { asprintf(&context->results.message, "Unable to delete original image (%s): %s\n", strerror(errno), context->src_path); result += RESULT_ERROR; } } // cleanup and report results context->results.result = result; dispatch_group_async_f(context->conv_group, dispatch_get_main_queue(), context, (void (*)(void *))finish_image); }
/** * Prints count lines on output with background bg. Lines can be scaled by using factor. * NOTE: This performs some filtering removing lines passing through origin */ void print_lines(char* output, char* bg, LINE_TYPE* lines, sizep_t count, double factor) { MagickWand *mw = NULL; DrawingWand *dw = NULL; PixelWand *pmw = NULL; unsigned long width, semi_width, height, semi_height; MagickWandGenesis(); mw = NewMagickWand(); dw = NewDrawingWand(); pmw = NewPixelWand(); MagickReadImage(mw, bg); width = MagickGetImageWidth(mw); semi_width = ceil(width/2.0); height = MagickGetImageHeight(mw); semi_height = ceil(height/2.0); PixelSetColor(pmw,"red"); DrawSetStrokeColor(dw, pmw); DrawSetStrokeWidth(dw, .5*factor); DrawSetStrokeAntialias(dw, 0); sizep_t n; for(n=0; n<count; n++) { LINE_TYPE cline = lines[n]; double m = -cos(cline.t)/sin(cline.t); double b = cline.r/sin(cline.t); if ((-0.5 < m && m < 0.5) || (-1 < b && b < 1)) continue; // remove lines too horizontal double x0 = - ((long) semi_width); double y0 = x0*m+b; double x1 = ((long) semi_width); double y1 = x1*m+b; // Apply factor x0 *= factor; y0 *= factor; x1 *= factor; y1 *= factor; // Fix coordinates and plot over the image DrawLine(dw, x0+semi_width, height-y0-semi_height, x1+semi_width, height-y1-semi_height); } MagickDrawImage(mw,dw); MagickWriteImage(mw, output); pmw = DestroyPixelWand(pmw); mw = DestroyMagickWand(mw); dw = DestroyDrawingWand(dw); MagickWandTerminus(); }
bool img_write (img_t *im, const char *file) { if (!im) { return false; } if (MagickWriteImage ((MagickWand *) im->screen, file) == MagickFalse) { img_exception ((MagickWand *) im->screen); return false; } return true; }
void saveImage(char* input,char* output) { printf("save-Image\n"); MagickWand *m_wand = NULL; MagickWandGenesis(); m_wand = NewMagickWand(); //open MagickReadImage(m_wand,input); //save MagickWriteImage(m_wand,output); /* Clean up */ if(m_wand)m_wand = DestroyMagickWand(m_wand); MagickWandTerminus(); }
void main(void) { MagickWand *mw = NULL; MagickWandGenesis(); /* Create a wand */ mw = NewMagickWand(); /* Read the input image */ MagickReadImage(mw,"logo:"); /* write it */ MagickSetImageColorspace(mw,GRAYColorspace); MagickWriteImage(mw,"gray.jpg"); /* Tidy up */ if(mw) mw = DestroyMagickWand(mw); MagickWandTerminus(); }
void flip(char* input,char* output) { printf("x-axis mirror\n"); MagickWand *m_wand = NULL; MagickWandGenesis(); m_wand = NewMagickWand(); //open MagickReadImage(m_wand,input); //flip MagickFlipImage(m_wand); //save MagickWriteImage(m_wand,output); /* Clean up */ if(m_wand)m_wand = DestroyMagickWand(m_wand); MagickWandTerminus(); }
int main(int argc, char* argv[]) { if (argc < 3) { fprintf (stderr, "Usage : %s IN_FILE OUT_FILE\n", argv[0]); exit(1); } MagickWand* m_wand; int w, h; MagickWandGenesis (); m_wand = NewMagickWand (); if (MagickReadImage (m_wand, argv[1]) == MagickFalse) { fprintf(stderr, "Cannot read image : %s\n", argv[1]); exit(1); } w = MagickGetImageWidth (m_wand); h = MagickGetImageHeight (m_wand); MagickResizeImage (m_wand, w/2, h/2, LanczosFilter, 1.0); MagickSetImageCompressionQuality (m_wand, QUALITY); if (MagickWriteImage (m_wand, argv[2]) == MagickFalse) { fprintf (stderr, "Cannot wright image : %s\n", argv[2]); exit(1); } if (m_wand) { m_wand = DestroyMagickWand (m_wnad); } MagickWandTerminus (); return 0; }
void rotatecw(char* input,char* output) { printf("clockwise 90\n"); MagickWand *m_wand = NULL; PixelWand * backpixel; MagickWandGenesis(); backpixel = NewPixelWand(); PixelSetColor(backpixel,"#000000"); m_wand = NewMagickWand(); //open MagickReadImage(m_wand,input); //rotate MagickRotateImage(m_wand,backpixel,90); //save MagickWriteImage(m_wand,output); /* Clean up */ if(m_wand)m_wand = DestroyMagickWand(m_wand); MagickWandTerminus(); }
int main (int argc, char **argv) { MagickWand *img = NULL; imag_t p1, *p; p=&p1; char *res; int i; MagickWandGenesis(); img = NewMagickWand(); if (argc > 1 && MagickReadImage(img, argv[1]) == MagickFalse) { fprintf(stderr, "Failed to read image!\n"); exit(EXIT_FAILURE); } /* Perform the required transform in image */ //MagickTransformImageColorspace(img, GRAYColorspace); // To gray colors //MagickThresholdImage(img, 40000); // Threshold //MagickNegateImage(img, MagickFalse); // Negate or invert black/white /* Extract image data */ p->x = MagickGetImageWidth(img); p->y = MagickGetImageHeight(img); p->p = malloc(p->x*p->y * sizeof(unsigned char)); MagickExportImagePixels(img, 0, 0, p->x, p->y, "I", CharPixel, p->p); /* Gocr library functions *************************************************/ gocr_ini(); /* Init a gocr job */ gocr_opts("0-9","#",NULL,0,0,0); /* only digits, "#" for unrecognized char */ res = gocr_call(p); /* Call gocr */ for (i=0; i < gocr_rows(); i++) printf("%s\n", gocr_resp(i)); /* Print response */ gocr_end(); /* End a gocr job */ /**************************************************************************/ /* Write processed image */ MagickWriteImage(img, "processed.png"); DestroyMagickWand(img); MagickWandTerminus(); exit(EXIT_SUCCESS); }
G_MODULE_EXPORT void cb_image_save_ok_clicked(GtkButton *button) { char *filename; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (camera_params.objects->imagesavedialog)); g_print("Saving to Filename %s\n",filename); if(camera_params.wand_data.saving_wand) { MagickBooleanType status; status=MagickSetImageFormat(camera_params.wand_data.saving_wand,"PNG"); if (status == MagickFalse) ThrowWandException(camera_params.wand_data.saving_wand); status=MagickWriteImage(camera_params.wand_data.saving_wand,filename); if (status == MagickFalse) ThrowWandException(camera_params.wand_data.saving_wand); DestroyMagickWand(camera_params.wand_data.saving_wand); } g_free (filename); camera_params.wand_data.saving_wand=NULL; gtk_widget_hide( camera_params.objects->imagesavedialog ); }
// just write an image to disk for testing bool ptImage::DumpImage(const char* FileName) const { long unsigned int Width = m_Width; long unsigned int Height = m_Height; MagickWand *mw; mw = NewMagickWand(); MagickSetSize(mw, Width, Height); MagickReadImage(mw,"xc:white"); MagickSetImageFormat(mw,"RGB"); MagickSetImageDepth(mw,16); MagickSetImageType(mw,TrueColorType); MagickSetImagePixels(mw,0,0,Width,Height,"RGB",ShortPixel,(unsigned char*) m_Data.data()); MagickSetImageDepth(mw,8); MagickSetImageCompression(mw, LZWCompression); bool Result = MagickWriteImage(mw, FileName); DestroyMagickWand(mw); return Result; }
int convert2jpg(const char *buff, const int len,const char *path){ //http://members.shaw.ca/el.supremo/MagickWand/resize.htm //MagickGetImageFormat MagickWand *m_wand = NULL; m_wand = NewMagickWand(); MagickReadImageBlob(m_wand, buff, len); //strip exif,GPS data MagickStripImage(m_wand); // Set the compression quality to 75 (high quality = low compression) MagickSetImageCompressionQuality(m_wand,75); /* Write the new image */ MagickWriteImage(m_wand,path); /* Clean up */ if(m_wand)m_wand = DestroyMagickWand(m_wand); return ZIMG_OK; }
void main(int argc,char* argv[]) { printf("%s\n%s\n",argv[1],argv[2]); MagickWand *m_wand = NULL; MagickWandGenesis(); m_wand = NewMagickWand(); //open MagickReadImage(m_wand,argv[1]); //blur MagickGaussianBlurImage(m_wand,0x4,0x8); //MagickBlurImage(m_wand,5,3); //save MagickWriteImage(m_wand,argv[2]); // Clean up if(m_wand)m_wand = DestroyMagickWand(m_wand); MagickWandTerminus(); }
//============================================================================== // We don't want to use the saving function of QImage, since this requires the // format plugins to be shipped. bool ptImageHelper::DumpImage(QImage* AImage, const QString AFileName) { long unsigned int Width = AImage->width(); long unsigned int Height = AImage->height(); MagickWand *mw; mw = NewMagickWand(); MagickSetSize(mw, Width, Height); MagickReadImage(mw,"xc:white"); MagickSetImageFormat(mw,"BGRA"); MagickSetImageDepth(mw,8); MagickSetImageType(mw,TrueColorType); MagickSetImagePixels(mw,0,0,Width,Height,"BGRA",CharPixel,(unsigned char*) AImage->bits()); MagickSetImageDepth(mw,8); MagickSetImageFormat(mw,"RGB"); MagickSetCompressionQuality(mw,95); MagickSetImageCompression(mw, LZWCompression); bool Result = MagickWriteImage(mw, AFileName.toLocal8Bit().data()); DestroyMagickWand(mw); return Result; }
apr_status_t dims_save_operation(dims_request_rec *d, char *args, char **err) { apr_status_t status; if (d->config->save_allowed) { MagickStatusType myflags; RectangleInfo myrec; myflags = ParseAbsoluteGeometry(args, &myrec); if (myrec.width < MagickGetImageWidth(d->wand) || myrec.height < MagickGetImageHeight(d->wand)) { dims_resize_operation(d, args, err); } if (MagickWriteImage(d->wand, d->r->filename) == MagickTrue) { status = DIMS_SAVED; } else { status = DIMS_FAILURE; } } else { status = DIMS_NOT_ALLOWED; } return status; }
void test_wand(void) { MagickWand *magick_wand = NULL; MagickWand *c_wand = NULL; DrawingWand *d_wand = NULL; PixelWand *p_wand = NULL; // Used for text effect #3 double dargs[1] = {120.}; // Used for text effect #5 double d_args[8] = { -0.02,0.0, 0.0,1.02, 0.0,0.0, -0.5,1.9 }; MagickWandGenesis(); // Text effect 1 - shadow effect using MagickShadowImage // This is derived from Anthony's Soft Shadow effect // convert -size 300x100 xc:none -font Candice -pointsize 72 \ // -fill white -stroke black -annotate +25+65 'Anthony' \ // \( +clone -background navy -shadow 70x4+5+5 \) +swap \ // -background lightblue -flatten -trim +repage font_shadow_soft.jpg //NOTE - if an image has a transparent background, adding a border of any colour other // than "none" will remove all the transparency and replace it with the border's colour magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); PixelSetColor(p_wand,"none"); // Create a new transparent image MagickNewImage(magick_wand,350,100,p_wand); // Set up a 72 point white font PixelSetColor(p_wand,"white"); DrawSetFillColor(d_wand,p_wand); DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Add a black outline to the text PixelSetColor(p_wand,"black"); DrawSetStrokeColor(d_wand,p_wand); // Turn antialias on - not sure this makes a difference DrawSetTextAntialias(d_wand,MagickTrue); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); // Trim the image down to include only the text MagickTrimImage(magick_wand,0); // equivalent to the command line +repage MagickResetImagePage(magick_wand,""); // Make a copy of the text image c_wand = CloneMagickWand(magick_wand); // Set the background colour to blue for the shadow PixelSetColor(p_wand,"blue"); MagickSetImageBackgroundColor(magick_wand,p_wand); // Opacity is a real number indicating (apparently) percentage MagickShadowImage(magick_wand,70,4,5,5); // Composite the text on top of the shadow MagickCompositeImage(magick_wand,c_wand,OverCompositeOp,5,5); if(c_wand)c_wand = DestroyMagickWand(c_wand); c_wand = NewMagickWand(); // Create a new image the same size as the text image and put a solid colour // as its background PixelSetColor(p_wand,"rgb(125,215,255)"); MagickNewImage(c_wand,MagickGetImageWidth(magick_wand),MagickGetImageHeight(magick_wand),p_wand); // Now composite the shadowed text over the plain background MagickCompositeImage(c_wand,magick_wand,OverCompositeOp,0,0); // and write the result MagickWriteImage(c_wand,"text_shadow.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(c_wand)c_wand = DestroyMagickWand(c_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 2 - tiled text using the builtin checkerboard pattern // Anthony's Tiled Font effect // convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \ // -tile pattern:checkerboard -annotate +28+68 'Anthony' \ // font_tile.jpg magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); set_tile_pattern(d_wand,"#check","pattern:checkerboard"); PixelSetColor(p_wand,"lightblue"); // Create a new transparent image MagickNewImage(magick_wand,320,100,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,28,68,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); // Trim the image MagickTrimImage(magick_wand,0); // Add a transparent border PixelSetColor(p_wand,"lightblue"); MagickBorderImage(magick_wand,p_wand,5,5); // and write it MagickWriteImage(magick_wand,"text_pattern.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 3 - arc font (similar to http://www.imagemagick.org/Usage/fonts/#arc) //convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \ // -annotate +25+65 'Anthony' -distort Arc 120 \ // -trim +repage -bordercolor lightblue -border 10 font_arc.jpg magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x100 lightblue canvas PixelSetColor(p_wand,"lightblue"); MagickNewImage(magick_wand,320,100,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); MagickDistortImage(magick_wand,ArcDistortion,1,dargs,MagickFalse); // Trim the image MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"lightblue"); MagickBorderImage(magick_wand,p_wand,10,10); // and write it MagickWriteImage(magick_wand,"text_arc.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 4 - bevelled font http://www.imagemagick.org/Usage/fonts/#bevel // convert -size 320x100 xc:black -font Candice -pointsize 72 \ // -fill white -annotate +25+65 'Anthony' \ // -shade 140x60 font_beveled.jpg magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x100 canvas PixelSetColor(p_wand,"gray"); MagickNewImage(magick_wand,320,100,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Set up a 72 point white font PixelSetColor(p_wand,"white"); DrawSetFillColor(d_wand,p_wand); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); // the "gray" parameter must be true to get the effect shown on Anthony's page MagickShadeImage(magick_wand,MagickTrue,140,60); #ifdef COLORIZE PixelSetColor(p_wand,"yellow"); DrawSetFillColor(d_wand,p_wand); cp_wand = NewPixelWand(); PixelSetColor(cp_wand,"gold"); MagickColorizeImage(magick_wand,p_wand,cp_wand); #endif // and write it MagickWriteImage(magick_wand,"text_bevel.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); #ifdef COLORIZE if(cp_wand)cp_wand = DestroyPixelWand(cp_wand); #endif // Text effect 5 and 6 - Plain text and then Barrel distortion // This one uses d_args magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x100 transparent canvas PixelSetColor(p_wand,"none"); MagickNewImage(magick_wand,320,100,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); MagickWriteImage(magick_wand,"text_plain.png"); // Trim the image MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"none"); MagickBorderImage(magick_wand,p_wand,10,10); // MagickSetImageMatte(magick_wand,MagickTrue); // MagickSetImageVirtualPixelMethod(magick_wand,TransparentVirtualPixelMethod); // d_args[0] = 0.1;d_args[1] = -0.25;d_args[2] = -0.25; [3] += .1 // The first value should be positive. If it is negative the image is *really* distorted d_args[0] = 0.0; d_args[1] = 0.0; d_args[2] = 0.5; // d_args[3] should normally be chosen such the sum of all 4 values is 1 // so that the result is the same size as the original // You can override the sum with a different value // If the sum is greater than 1 the resulting image will be smaller than the original d_args[3] = 1 - (d_args[0] + d_args[1] + d_args[2]); // Make the result image smaller so that it isn't as likely // to overflow the edges // d_args[3] += 0.1; // 0.0,0.0,0.5,0.5,0.0,0.0,-0.5,1.9 d_args[3] = 0.5; d_args[4] = 0.0; d_args[5] = 0.0; d_args[6] = -0.5; d_args[7] = 1.9; // DON'T FORGET to set the correct number of arguments here MagickDistortImage(magick_wand,BarrelDistortion,8,d_args,MagickTrue); // MagickResetImagePage(magick_wand,""); // Trim the image again MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"none"); MagickBorderImage(magick_wand,p_wand,10,10); // and write it MagickWriteImage(magick_wand,"text_barrel.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 7 - Polar distortion // This one uses d_args[0] magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x200 transparent canvas PixelSetColor(p_wand,"none"); MagickNewImage(magick_wand,320,200,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); d_args[0] = 0.0; // DON'T FORGET to set the correct number of arguments here MagickDistortImage(magick_wand,PolarDistortion,1,d_args,MagickTrue); // MagickResetImagePage(magick_wand,""); // Trim the image again MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"none"); MagickBorderImage(magick_wand,p_wand,10,10); // and write it MagickWriteImage(magick_wand,"text_polar.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 8 - Shepard's distortion // This one uses d_args[0] magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x200 transparent canvas PixelSetColor(p_wand,"none"); MagickNewImage(magick_wand,640,480,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,50,240,(const unsigned char *)"Magick Rocks"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); d_args[0] = 150.0; d_args[1] = 190.0; d_args[2] = 100.0; d_args[3] = 290.0; d_args[4] = 500.0; d_args[5] = 200.0; d_args[6] = 430.0; d_args[7] = 130.0; // DON'T FORGET to set the correct number of arguments here MagickDistortImage(magick_wand,ShepardsDistortion,8,d_args,MagickTrue); // Trim the image MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"none"); MagickBorderImage(magick_wand,p_wand,10,10); // and write it MagickWriteImage(magick_wand,"text_shepards.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); MagickWandTerminus(); }
// Write Image bool ptImage::ptGMCWriteImage(const char* FileName, const short Format, const int Quality, const int Sampling, const int Resolution, const char* ColorProfileFileName, const int Intent) { long unsigned int Width = m_Width; long unsigned int Height = m_Height; MagickWand *mw; mw = NewMagickWand(); MagickSetSize(mw, Width, Height); MagickReadImage(mw,"xc:white"); MagickSetImageFormat(mw,"RGB"); MagickSetImageDepth(mw,16); MagickSetImageType(mw,TrueColorType); MagickSetImagePixels(mw,0,0,Width,Height,"RGB",ShortPixel,(unsigned char*) m_Image); // Color profile // Color profile in PNG is not supported, due to limitations in imagemagick if (ColorProfileFileName != NULL) { FILE* pFile = fopen (ColorProfileFileName, "rb" ); if (pFile==NULL) { ptLogError(ptError_FileOpen,FileName); exit(EXIT_FAILURE); } fseek (pFile , 0 , SEEK_END); long lSize = ftell (pFile); rewind (pFile); uint8_t* pchBuffer = (uint8_t*) CALLOC(lSize,sizeof(uint8_t)); ptMemoryError(pchBuffer,__FILE__,__LINE__); size_t RV = fread (pchBuffer, 1, lSize, pFile); if (RV != (size_t) lSize) { ptLogError(ptError_FileOpen,FileName); exit(EXIT_FAILURE); } MagickSetImageProfile(mw,"ICC",pchBuffer,lSize); FCLOSE (pFile); FREE (pchBuffer); } // Redering intent switch(Intent) { case 0: MagickSetImageRenderingIntent(mw,PerceptualIntent); break; case 1: MagickSetImageRenderingIntent(mw,RelativeIntent); break; case 2: MagickSetImageRenderingIntent(mw,SaturationIntent); break; case 3: MagickSetImageRenderingIntent(mw,AbsoluteIntent); break; default: assert(0); } // Depth if ((Format==ptSaveFormat_TIFF8) || (Format==ptSaveFormat_PPM8) || (Format==ptSaveFormat_JPEG) || (Format==ptSaveFormat_PNG)) { MagickSetImageDepth(mw,8); } // Jpeg Sampling double factors111[3] = {1.0,1.0,1.0}; double factors211[3] = {2.0,1.0,1.0}; if (Format==ptSaveFormat_JPEG) { if (Sampling==ptSaveSampling_111) { MagickSetSamplingFactors(mw,3,factors111); } else { MagickSetSamplingFactors(mw,3,factors211); } } // Quality if (Format==ptSaveFormat_PNG || Format==ptSaveFormat_PNG16) MagickSetCompressionQuality(mw, floor((double) Quality/10.0)*10+5); else MagickSetCompressionQuality(mw,Quality); // Compression if ((Format==ptSaveFormat_TIFF8) || (Format==ptSaveFormat_TIFF16)) { MagickSetImageCompression(mw, LZWCompression); } // Resolution MagickSetImageUnits(mw, PixelsPerInchResolution); MagickSetImageResolution(mw, Resolution, Resolution); bool Result = MagickWriteImage(mw, FileName); DestroyMagickWand(mw); return Result; }
int main(int argc, char *argv[]) { MagickWand *wand, *input, *output; MagickBooleanType status; printf("Add 3 sets of images after setting 'first' on empty wand\n"); printf("Result shoud be: 678 345 012\n"); MagickWandGenesis(); wand = NewMagickWand(); input = NewMagickWand(); MagickSetFirstIterator(wand); status = MagickReadImage(input, "font_0.gif" ) && MagickReadImage(input, "font_1.gif" ) && MagickReadImage(input, "font_2.gif" ); if (status == MagickFalse) ThrowWandException(input); status = MagickAddImage(wand, input); if (status == MagickFalse) ThrowWandException(wand); ClearMagickWand(input); status = MagickReadImage(input, "font_3.gif" ) && MagickReadImage(input, "font_4.gif" ) && MagickReadImage(input, "font_5.gif" ); if (status == MagickFalse) ThrowWandException(input); status = MagickAddImage(wand, input); if (status == MagickFalse) ThrowWandException(wand); ClearMagickWand(input); status = MagickReadImage(input, "font_6.gif" ) && MagickReadImage(input, "font_7.gif" ) && MagickReadImage(input, "font_8.gif" ); if (status == MagickFalse) ThrowWandException(input); status = MagickAddImage(wand, input); if (status == MagickFalse) ThrowWandException(wand); input=DestroyMagickWand(input); /* finished */ /* append all images together to create the output wand */ MagickResetIterator(wand); /* append all images */ output = MagickAppendImages(wand,MagickFalse); wand = DestroyMagickWand(wand); /* finished - could swap here */ /* Final output */ status = MagickWriteImage(output,"show:"); if (status == MagickFalse) ThrowWandException(output); output = DestroyMagickWand(output); MagickWandTerminus(); }
int main(int argc,char **argv) { unsigned int width, height,seed; double pos[2] = {0,0},target_pos[2], diff[3],min_col_diff; struct kdres *neigh; void *kd; //kd-tree int i,x,y,c,num_cells=500,random; size_t row_size;//imagemagick wants this char source_filename[50] = "lisa.png"; char dest_filename[59];//I set to 59 so user could have 49 chars + 10 in the default case of NNNNNN-sourcefilename int oflag=0,sflag=0,vflag=0,cflag=0; //imagemagick stuff MagickWand *source,*dest; PixelWand *neigh_color,*color,**pmw; PixelIterator *imw; while((c = getopt(argc,argv,"vc:n:s:r:d:")) != -1) { switch (c) { case 'v': vflag=1; break; case 'n': num_cells=atoi(optarg); break; case 's': strcpy(source_filename,optarg); break; case 'd': oflag=1; strcpy(dest_filename,optarg); break; case 'r': if((seed=atoi(optarg))!=0) sflag=1; break; case 'c': cflag=1; min_col_diff = atof(optarg); break; default: printf("Option %s not recognized and ignored.\n",c); } } if(!oflag) sprintf(dest_filename,"%d-%s",num_cells,source_filename); MagickWandGenesis(); source=NewMagickWand(); dest = NewMagickWand(); color = NewPixelWand(); neigh_color = NewPixelWand(); pmw = NewPixelWand(); MagickReadImage(source,source_filename); if (source==MagickFalse) { printf("Error reading file. Usage: vor filename\n"); return 1; } width = MagickGetImageWidth(source); height = MagickGetImageHeight(source); printf("File has width %d and height %d\n", width, height); if(!sflag) { //seed the algorithm with /dev/random if a seed wasn't specified random = open("/dev/random", 'r'); read(random, &seed, sizeof (seed)); close(random); } if(vflag) printf("seed : %d\n",seed); srand(seed); kd = kd_create(2); if(cflag) { for(i = 0; i < num_cells; i++) { pos[0]= (double)random_in_range(0,width); pos[1]= (double)random_in_range(0,height); if(pixel_compare_NN(min_col_diff,source,kd,pos,color,neigh_color)) kd_insert(kd,pos,0); } } else { for(i = 0; i < num_cells; i++) { pos[0]= (double)random_in_range(0,width); pos[1]= (double)random_in_range(0,height); kd_insert(kd,pos,0); } } MagickSetSize(dest,width,height); MagickReadImage(dest,"xc:none"); imw = NewPixelIterator(dest); for (y=0; y < height; y++) { pos[1] = y; pmw = PixelGetNextIteratorRow(imw, &row_size); //we iterate through the rows, grabbing one at a time for (x=0; x < (long) width; x++) { pos[0] =x; neigh = kd_nearest(kd,pos);//this is the query kd_res_item(neigh, target_pos);//then we pull out the result into target_pos kd_res_free(neigh);//need to free the memory used for the query MagickGetImagePixelColor(source,target_pos[0],target_pos[1],color); PixelSetColorFromWand(pmw[x],color); } PixelSyncIterator(imw);//this will write to the image (MagickWand) } if(vflag)printf("Writing to file %s.\n",dest_filename); if(MagickWriteImage(dest,dest_filename)==MagickFalse) { printf("Error writing to file %s.\n",dest_filename); } source=DestroyMagickWand(source); dest=DestroyMagickWand(dest); MagickWandTerminus(); kd_free(kd); return 0; }
void generate(char *source_image_path, char *sink_image_path, char *top_text, char *bottom_text) { MagickWand *wand = NULL; DrawingWand *drawing_wand = NULL; PixelWand *pixel_wand = NULL; MagickWandGenesis(); wand = NewMagickWand(); drawing_wand = NewDrawingWand(); pixel_wand = NewPixelWand(); // read base image MagickReadImage(wand, source_image_path); ssize_t width; ssize_t pointsize; ssize_t stroke_width; double scale; char formatted_text[100] = { '\0' }; // Scale text width = MagickGetImageWidth(wand); scale = scaleText(top_text, formatted_text); pointsize = width / 5.0; stroke_width = pointsize / 30.0; // Draw top text PixelSetColor(pixel_wand, "white"); DrawSetFillColor(drawing_wand, pixel_wand); DrawSetFont(drawing_wand, "Impact"); DrawSetFontSize(drawing_wand, pointsize * scale); DrawSetFontWeight(drawing_wand, 700); DrawSetGravity(drawing_wand, NorthGravity); // Add a black outline to the text PixelSetColor(pixel_wand, "black"); DrawSetStrokeWidth(drawing_wand, stroke_width * scale); DrawSetStrokeColor(drawing_wand, pixel_wand); // Turn on Anitalias DrawSetTextAntialias(drawing_wand, MagickTrue); // Draw the text DrawAnnotation(drawing_wand, 0, 0, (const unsigned char *)formatted_text); if (bottom_text) { char formatted_bottom_text[100] = { '\0' }; // Scale text width = MagickGetImageWidth(wand); scale = scaleText(bottom_text, formatted_bottom_text); pointsize = width / 5.0; stroke_width = pointsize / 30.0; // Draw bottom text PixelSetColor(pixel_wand, "white"); DrawSetFillColor(drawing_wand, pixel_wand); DrawSetFont(drawing_wand, "Impact"); DrawSetFontSize(drawing_wand, pointsize * scale); DrawSetFontWeight(drawing_wand, 700); DrawSetGravity(drawing_wand, SouthGravity); // Add a black outline to the text PixelSetColor(pixel_wand, "black"); DrawSetStrokeWidth(drawing_wand, stroke_width * scale); DrawSetStrokeColor(drawing_wand, pixel_wand); // Turn on Anitalias DrawSetTextAntialias(drawing_wand, MagickTrue); // Draw the text DrawAnnotation(drawing_wand, 0, 0, (const unsigned char *)formatted_bottom_text); } // Draw the image on the magick wand MagickDrawImage(wand, drawing_wand); // Write the image if (sink_image_path) { MagickWriteImage(wand, sink_image_path); } else { MagickWriteImageFile(wand, stdout); } // Clean up if(pixel_wand) pixel_wand = DestroyPixelWand(pixel_wand); if(drawing_wand) drawing_wand = DestroyDrawingWand(drawing_wand); if(wand) wand = DestroyMagickWand(wand); MagickWandTerminus(); }
/* gcc -o imagick imagick-landscape-3d.c -Wall -Werror -I/usr/include/ImageMagick -lMagickWand */ int main() { MagickWand *mw, *canvas; PixelWand *pw; DrawingWand *line; size_t w, h, offset; int x, y, r, g, b, grey, lh; MagickBooleanType mbt; MagickWandGenesis(); /* startup */ mw = NewMagickWand(); mbt = MagickReadImage(mw, PNG_IN_FILE); assert(mbt == MagickTrue); w = MagickGetImageWidth(mw); h = MagickGetImageHeight(mw); pw = NewPixelWand(); PixelSetColor(pw, "transparent"); mbt = MagickShearImage(mw, pw, 45, 0); assert(mbt == MagickTrue); w = MagickGetImageWidth(mw); h = MagickGetImageHeight(mw); mbt = MagickScaleImage(mw, w, h/2); assert(mbt = MagickTrue); w = MagickGetImageWidth(mw); h = MagickGetImageHeight(mw); canvas = NewMagickWand(); MagickGetImagePixelColor(mw, 0, 0, pw); MagickNewImage(canvas, w, h*2, pw); offset = h; for (x = 0; x < w; ++x) { line = NewDrawingWand(); lh = 0; for (y = h-1; y >= 0; --y) { if (MagickGetImagePixelColor(mw, x, y, pw) == MagickFalse) continue; r = 255 * PixelGetRed(pw); g = 255 * PixelGetGreen(pw); b = 255 * PixelGetBlue(pw); grey = (r + g + b)/5; if (lh == 0 || lh < grey) { DrawSetFillColor(line, pw); DrawSetStrokeColor(line, pw); DrawLine(line, x, y + offset - lh, x, y - grey + offset); lh = grey; } lh--; } MagickDrawImage(canvas, line); DestroyDrawingWand(line); } MagickScaleImage(canvas, w - h, h * 2); mbt = MagickSetImageFormat(canvas, "png"); assert(mbt == MagickTrue); mbt = MagickWriteImage(canvas, PNG_OUT_FILE); assert(mbt == MagickTrue); pw = DestroyPixelWand(pw); mw = DestroyMagickWand(mw); canvas = DestroyMagickWand(canvas); MagickWandTerminus(); /* shutdown */ return 0; }