I'm converting pdf files to images with ImageMagic, everything is ok until I use -resize option, then I get image with black background. I use this command:
convert -density 400 image.pdf -resize 25% image.png
I need to use -resize option otherwise I get really large image. Is there any other option which I can use to resize image or is there option to set background in white.
That's not a Ghostscript command, You will need to find out what convert is sending to Ghostscript. As it stands I can't even be sure that your problem is with Ghostscript ,since it could easily be something that convert is doing.
Solved it by removing alpha from image, it seems imagemagic tries to apply some opacity but since jpeg doesn't allow transperency result was black background. So I found example on imagemagic website and it helped me:
convert a.pdf -background skyblue -alpha remove -alpha off a_remove.jpg
Related
I've got a 16x512 image comprised of 16x16 images. I want to seperate them, individually scale each one down to 16x8, then put them all back into their full 16x512. I've got a basic idea, but I'm having trouble executing it.
Using the commands from unix stackexchange, I split by file by using convert -crop 16x16 my_image.png crop-%d.png, which yields 32 images (512 / 16 == 32). My next step was where trouble has started. From askubuntu, I found the command mogrify -resize 16x8 crop-*.png, however this does not yield 16x8 images, but rather 8x8, which I do not want. Furthermore, this post on stackoverflow gives me the command for merging these images, which is convert crop-*.png -append my_image_cropped.png, however it does not yield a 16x512 like I want, but rather 8x256 (the 8 is due to the previous bug, but I still want a height of 512, not 256).
What do I need to accomplish my goals? The image in question can be found on imgur.
Edit: Here are some images which will describe the basic idea
The full image:
Both 16x16 and 16x8 side by side
The finalized image, basically the 16x8 will sit in the 16x16 area (right at the bottom part, that is essential), but won't fully fill it.
I am not sure I understand what you want to do. But if you resize 16x8, Imagemagick will keep aspect ratio. If you want to force it to be exactly 16x8 and can accept distortion, then use the ! flag. But you then say you want to put the 32 pieces back to form 16x512, but the resize will make it 16x256, since you have 32 image of height 8. So you have to resize again. Here is how to do that, if that is really what you want.
Create a gradient image for testing:
convert -size 16x512 gradient: grad.png
Do the processing:
convert grad.png -crop 16x16 -resize 16x8! -append -resize 16x512! newgrad.png
Note that proper Imagemagick syntax reads the input first.
ADDITION:
Given your new information in your comment, try this:
convert grad.png -crop 16x16 -resize 16x8 -gravity northwest -background none -extent 16x16 -append newgrad.png
Change the background color as desired and the gravity setting as desired for positioning.
I want to resize image to an exact size by maintaining aspect ratio and filling the empty space with transparency using nodejs.
I am able to do it using canvas. But due to some server os issues I can not use canvas.
I tried with imageMagick and gm. But couldn't find any option like these. Please show me a way to do this.
Thanks in advance.
In ImageMagick, you can resize and fill to the exact size by
convert image -resize WxH -background none -gravity center -extent WxH output
Input:
Here I will make the background black so you can see that if fills it out.
convert lena.jpg -resize 400x300 -background black -gravity center -extent 400x300 lena1.jpg
In case you have been successful using the canvas for resizing images, you can check out https://github.com/Automattic/node-canvas this repo.
As already mentioned you also resize images using ImageMagick by processes in NodeJS ( http://www.imagemagick.org/Usage/resize/ )
convert dragon.gif -resize 64x64 resize_dragon.gif
In case you have a lot of images, I would suggest that you write a terminal script ( NodeJS can achieve that as well ).
I hope it helps, in case you have more queries, feel free to ask.
I am using GraphicsMagick and I am trying to create a 200px by 200px transparent TIF image. However, the resulting image, when opened in Photoshop, has a black background. If I use ImageMagick, it works.
The following ImageMagick command creates a transparent image (when opened in Photoshop)
magick convert -size 200x200 xc:transparent transparent1.tif
But, the same GraphicsMagic command creates a black image (when opened in Photoshop)
gm convert -size 200x200 xc:transparent transparent2.tif
I am at a loss. I would like to use GraphicsMagic because the Node API has streaming support and provides some other nice features.
I need to offset the pixels in a PNG image by -1 in X and -4 in Y axis.
The images were converted from a PDF created by Corel Draw, which adds an offset, breaking the image processing system I'm working on.
align_image_stack from hugin-tools package crashes when processing these files, that's why I resort to trying a fixed offest correction.
I tried this these commands:
$ convert a.png: -geometry 100%-100-100 b.png
$ convert -region '100%+500px+100px' a.png b.png
$ convert -page '100%+500px+100px' a.png b.png
$ convert -repage '100%+500px+100px' a.png b.png
$ convert -crop '100%+500px+100px' a.png b.png
$ convert a.png -geometry 100%-100px-100px b.png
They have all finished without an error, but the gave me the same image I fed them as input.
a.png = b.png
What am I doing wrong? Why the Covert command does not shift the image contents?
EDIT:
Here's a pair of images to illustrate my problem. The first image is what I want, the second is what comes out of Corel Draw, I want to apply an arbitrary X/Y offset to compensate for this difference. The images are faked only to illustrate the problem, this is not authentic data.
New point is that I was able to produce the offset once, but I can't reproduce this. It looks to me like a bug in ImageMagick, because I'm trying the same command that I used before and it doesn't work now.
I also tried using GraphicsMagick to doublechek this.
I was able to get an offset written to PNG header, but that doesn't make Blender use that offset, so I need to "burn" that offset into the bitmap data, not just specify it in the metadata.
This command did a change, but only GIMP seems understands that and I need to make Blender apply the offset:
convert a.png -repage '100%x100%+100+1000' b.png
I tried using -sample to apply the transformation, but it's not alpplied and stays in the metadata - I can check this with GIMP.
convert a.png -repage '100%x100%+100+1000' -sample 100% b.png
I can't believe I am unable to do such a simple thing.
Updated Answer
It is hard to understand what you want without proper images, but here is another attempt at guessing a solution for you. Let's start with this image - ignore the colours as I only added them so you can see the extent of the images and you can remove/change them anyway:
The new plan is to trim your image so there is no border around the letters at all and then to add in whatever border you want afterwards. So, trimming the existing border and adding a 10px border left and right and a 50px border top and bottom:
convert start.png -trim -bordercolor red -border 10x50 result.png
Or, trimming the original border and adding a 10px border to the right side only:
convert start.png -trim -gravity east -background blue -splice 10x0 result.png
Hopefully that will give you an approach to achieve what you seek.
Original Answer
If you want to reset the page offsets back to zero, the easiest way is:
mogrify +repage image.png
Or, slightly harder:
convert image.png +repage result.png
my shell hangs on this command:
/usr/local/bin/convert -size 298x71 -background black -fill white -stroke none -gravity center -trim -interline-spacing 0 -font /home/amazingw/public_html/live/fonts/Phillies.ttf label:'150' png:-
The shell just sits there until i press ctrl+c. If I add any letter to the label: argument the command runs fine and I get output.
The font is there but it is missing the number characters in the definition.
Could that cause my command to fail?
This seems like an issue related to input at the console, I am assuming you are using Bash.
If this is the case, Bash is trying to interpret the quotes and is waiting for other input.
after reviewing the imagemagick website for "label:"
Label - Simple Text Label
Basic Labels
Creating a font image using a "label:" image,
is the more typical way of drawing a font
quickly in ImageMagick...
It goes on and gives many examples...
convert -background lightblue -fill blue \
-font Candice -pointsize 72 label:Anthony \
label.gif
None of the examples show single quotes.
I would assume between Bash and ImageMagick's convert program, there is some error on interpretation of input from the console.
I would suggest trying your same command without quotes
/usr/local/bin/convert -size 298x71 -background black -fill white -stroke none -gravity center -trim -interline-spacing 0 -font /home/amazingw/public_html/live/fonts/Phillies.ttf label:150 png:-
I would also take a quick look at the Bash manual about single quotes too.
I was able to test using a modified version of the font which contained the digits. Command went smoothly and an output image was returned. This pretty much narrows it down to an ImageMagick problem with handling labels. Looks like if the label is made out only of characters which are missing in the font (the resulting output image would be empty) - in that case ImageMagick hangs until ctrl+c is pressed - especially problematic as I'm running this from php's proc_open.