how to dig a hole of specified size from a JPG image
how to dig a hole of specified size from a JPG image
I want to dig a hole of specified size from a JPG image specified location to generate a PNG image. In order to reduce the size of the image, the PNG should be 8 bit. Thank you.The sample diagram is as follows:
before:
after:
before:
after:
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: how to dig a hole of specified size from a JPG image
What version of IM, on what platfom?
I assume you want 8 bits/channel/pixel, which JPG is anyway.
I assume you want 8 bits/channel/pixel, which JPG is anyway.
Code: Select all
magick in.jpg -region 300x400+20+30 -alpha transparent +region -depth 8 out.png
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: how to dig a hole of specified size from a JPG image
Please do not send messages as warnings. I have deleted your warning and posted it here:
Thank you very much!The version I used was 6.9.1-10, and I used this command:
magick in.jpg -region 300x400+20+30 -alpha transparent +region -depth 8 out.png
igenerate a fully transparent image, not the result I wanted.Would you please see what the problem is?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: how to dig a hole of specified size from a JPG image
"magick" is a v7 command, but you have v6, so I'm surprised that works at all.
In some versions, "-region" didn't work. This longer command does the same job:
In some versions, "-region" didn't work. This longer command does the same job:
Code: Select all
convert in.jpg ( +clone -fill White -colorize 100 -fill Black -draw "rectangle 20,20,320,430" ) -alpha off -compose CopyOpacity -composite -depth 8 out.png
snibgo's IM pages: im.snibgo.com
Re: how to dig a hole of specified size from a JPG image
Thank you so much!This works!How do I implement this with the MagickWand C API?snibgo wrote: ↑2018-11-27T18:57:26-07:00 "magick" is a v7 command, but you have v6, so I'm surprised that works at all.
In some versions, "-region" didn't work. This longer command does the same job:
Code: Select all
convert in.jpg ( +clone -fill White -colorize 100 -fill Black -draw "rectangle 20,20,320,430" ) -alpha off -compose CopyOpacity -composite -depth 8 out.png
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: how to dig a hole of specified size from a JPG image
By starting small. Find the C MagickWand functions that correspond to the CLI operations: read, colorize, draw, composite, write. Then write the program.dxr528 wrote:How do I implement this with the MagickWand C API?
snibgo's IM pages: im.snibgo.com
Re: how to dig a hole of specified size from a JPG image
// +clone -fill White -colorize 100
MagickWand *im_clone = NewMagickWand();
im_clone=CloneMagickWand(larg->img);
PixelWand* tone = NewPixelWand();
PixelSetColor(tone, "white");
PixelWand* opacity2 = NewPixelWand();
PixelSetColor(opacity2, "rgb(100%,100%,100%)");
MagickColorizeImage(im_clone, tone, opacity2);
DestroyPixelWand(tone);
DestroyPixelWand(opacity2);
// -fill Black -draw "rectangle 20,20,320,430"
PixelWand *p_wand = NULL;
DrawingWand *d_wand = NULL;
p_wand = NewPixelWand();
d_wand = NewDrawingWand();
PixelSetColor(p_wand,"Black");
DrawSetFillColor(d_wand,p_wand);
DrawRectangle(d_wand, 20,20,320,430 );
MagickDrawImage(im_clone, d_wand);
DestroyPixelWand(p_wand);
DestroyDrawingWand(d_wand);
// -alpha off -compose CopyOpacity -composite -depth 8
// ActivateAlphaChannel, DeactivateAlphaChannel, OpaqueAlphaChannel, or SetAlphaChannel.
MagickSetImageAlphaChannel(larg->img, OpaqueAlphaChannel);
MagickCompositeImage(larg->img,im_clone,CopyOpacityCompositeOp,0,0);
int ret = MagickSetImageDepth(larg->img, 8 );
my code is like that,but it do not work.please help me. thank you.
how to change command -alpha off to MagickWand in V6?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: how to dig a hole of specified size from a JPG image
The CLI "-alpha off" operates on all the images in the current list, not just one.
When debugging any image processing, it is useful to write image files at the different stages, eg im_clone after each process. Then, when the result is wrong, you can find which part is wrong.
When debugging any image processing, it is useful to write image files at the different stages, eg im_clone after each process. Then, when the result is wrong, you can find which part is wrong.
snibgo's IM pages: im.snibgo.com
Re: how to dig a hole of specified size from a JPG image
i saved im_clone to local img file.just like this:snibgo wrote: ↑2018-11-28T07:01:08-07:00 The CLI "-alpha off" operates on all the images in the current list, not just one.
When debugging any image processing, it is useful to write image files at the different stages, eg im_clone after each process. Then, when the result is wrong, you can find which part is wrong.
and the last png file like this:
Last edited by dxr528 on 2018-11-28T08:55:42-07:00, edited 1 time in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: how to dig a hole of specified size from a JPG image
Why are they different sizes?
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: how to dig a hole of specified size from a JPG image
"-alpha off" deactivates the alpha channel, so CopyOpacity will copy from the intensity, not from the alpha channel. By contrast, setting alpha to opaque activates the alpha channel, setting all pixels opaque, and that's not what you want.
snibgo's IM pages: im.snibgo.com
Re: how to dig a hole of specified size from a JPG image
// 1 add mask :convert before.jpg -fill black -colorize 30% result.jpg
PixelWand *colorize = NewPixelWand();
PixelWand *opacity = NewPixelWand();
PixelSetColor(colorize,"black");
PixelSetColor(opacity, "rgb(30%,30%,30%)");
MagickColorizeImage(larg->img,colorize,opacity);
DestroyPixelWand(colorize);
DestroyPixelWand(opacity);
MagickSetImageCompressionQuality(larg->img, 75);
// 2 hollow : convert result.jpg \( +clone -fill White -colorize 100 -fill Black -draw "rectangle 20,20,320,430" \)
// -alpha off -compose CopyOpacity -composite -depth 8 out.png
// +clone -fill White -colorize 100
MagickWand *im_clone = NewMagickWand();
im_clone=CloneMagickWand(larg->img);
PixelWand* tone = NewPixelWand();
PixelSetColor(tone, "white");
PixelWand* opacity2 = NewPixelWand();
PixelSetColor(opacity2, "rgb(100%,100%,100%)");
MagickColorizeImage(im_clone, tone, opacity2);
DestroyPixelWand(tone);
DestroyPixelWand(opacity2);
// -fill Black -draw "rectangle 20,20,320,430"
PixelWand *p_wand = NULL;
DrawingWand *d_wand = NULL;
p_wand = NewPixelWand();
d_wand = NewDrawingWand();
PixelSetColor(p_wand,"Black");
DrawSetFillColor(d_wand,p_wand);
DrawRectangle(d_wand, x,y,x+w,y+h);
MagickDrawImage(im_clone, d_wand);
DestroyPixelWand(p_wand);
DestroyDrawingWand(d_wand);
// -alpha off -compose CopyOpacity -composite -depth 8
// ActivateAlphaChannel, DeactivateAlphaChannel, OpaqueAlphaChannel, or SetAlphaChannel.
MagickSetImageAlphaChannel(im_clone, DeactivateAlphaChannel);
MagickSetImageAlphaChannel(larg->img, DeactivateAlphaChannel);
MagickSetImageDepth(larg->img, 8 );
MagickSetImageDepth(im_clone, 8 );
MagickSetFormat(larg->img, "png");
int ret = MagickCompositeImage(larg->img,im_clone,CopyOpacityCompositeOp,0,0);
Thank you for your suggestion. After modifying the code, it is ok now.But now the generated PNG image size is relatively large. Is there any way to compress it?I hope to get your help.thank you.
this is the final png img.the size is 282Kb.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: how to dig a hole of specified size from a JPG image
pngcrush reduces the size by 27%.
snibgo's IM pages: im.snibgo.com