I try to convert SVG to PNG. Result picture has a white background I need transparent.
Sample of code:
wand = NewMagickWand()
MagickReadImage(wand,tmp_file_name)
transparentColor = NewPixelWand()
PixelSetMagickColor(transparentColor, 'none')
MagickSetBackgroundColor(wand, transparentColor)
MagickWriteImage(wand,new_filename)
if I do in command-line:
convert -background 'transparent' ./media/2222222.svg ./media/2222222.png
I've got a transparent picture.
I used subprocess and I got what I want
args = ['convert', '-background', 'transparent', './media/2222222.svg', './media/2222222.png',]
result = subprocess.call(args)
Related
I have problem with PNG sRGB rednering in Three.js. I have this piece of code where I am generation texture from SVG file:
(...) // managing whole SVG data which is long and not important as I will show below
window.temCanvas = document.createElement('canvas');
temCanvas.width = '2048';
temCanvas.height = '454';
window.temContext = temCanvas.getContext('2d', {colorSpace: "srgb", preserveDrawingBuffer: true});
temContext.clearRect(0, 0, 2048, 454);
temContext.drawImage(newTextureTopSVG, 0,0, 2048, 454);
var newTex1 = temCanvas.toDataURL("image/png"); // here should be info about sRGB?
Texture generated this way is showing different colors. All 0 and 255 values are showing correctly but when it is between i.e. rgb(0,128,255) should look like this:
but it is rendered as:
I saved png generated from SVG and compared it to similar png generated from graphic software, there is difference which I see in Notepad++, correct file contain this:
file which is rendering badly (after saving from canvas in Firefox) doesn't contain srgb text:
I suppose I have to add sRGB info here:
var newTex1 = temCanvas.toDataURL("image/png");
How to do it? But shouldn't it be always sRGB for PNG?
Maybe I am wrong and it is possible to force Three.js to show colors correctly by changing something in Material, Texture etc.?
I am using:
renderer.outputEncoding = sRGBEncoding;
I don't want to provide all data, I will edit this post if needed. It is way too long. Especially managing SVG data.
When using renderer.outputEncoding = sRGBEncoding;, sRGB encoded color textures must be configured like so:
texture.encoding = sRGBEncoding;
Otherwise the sRGB workflow is incomplete resulting in wrong colors.
I'm trying to convert some similar images from gif to png.
You can find two of the pictures here:
https://europa.eu/european-union/about-eu/history/1980-1989_en.
After converting the first gif (for the year 1981), you can see the background colour is the same as before, white, but for the second gif (for the year 1986), the background colour changed to pink. How to fix it?
Below is my code:
file_in = uigetfile('*.*', 'All Files', 'MultiSelect','on');
file_out = cellfun(#(x) cat(2, x(1:(length(x)-3)), 'png'),...
file_in, 'UniformOutput', false);
for i = 1: length(file_in)
[gif,map] = imread (file_in{i});
imwrite (gif, map, file_out{i}, 'Background', [0 0 0]);
end
Matlab have never change the image color after conversion. Thus, if you try to open the 'gif' or 'png' by imshow you will get the same result.
Whatever, if you want to change the background color to white use this code.
So I have this base image:
And in photoshop I do a basic layer color overlay, with the rgb colors:
r: 244, g: 93, b: 0
This gives me the amazingly vibrant:
What I'm trying to do is colorize the same image in rmagick, so if I do the following colorize:
img = Magick::Image.read('brush.png').first
img = img.colorize(100, 100, 100, Magick::Pixel.new(244, 93, 0, 1))
img.format = 'png'
img.to_blob
It gives me this really washed out orange image:
My questions is, how do I colorize this image with those rgb params in imagemagick / rmagick, to get the same vibrant color that I got in photoshop.
Thanks.
At the commandline, I think you want something like this:
convert brush.png \( +clone -fill "rgb(244,93,0)" -colorize 100% \) -compose colorize -composite out.png
So, with the +clone I am creating another layer the same size as your image and entirely filling it 100% with your orange colour and then composing it over your image with the -composite to blend the opacity and colour.
I really don't speak Ruby, but I think it will be along these lines:
#!/usr/bin/ruby
require 'RMagick'
include Magick
infile=ARGV[0]
img=Magick::Image.read(infile).first
w=img.columns
h=img.rows
ovl=Image.new(w,h){self.background_color=Magick::Pixel.new(244*256,93*256,0)}
img.composite!(ovl,0,0,Magick::ColorizeCompositeOp)
img.write('result.png')
Mark Setchell's command line works for me (Windows), with slight modifications...
convert greyscale.png +clone -fill "rgb(244,93,0)" -colorize 100% -compose colorize -composite colour.png
Found this link on recolouring with rmagick...
ftp://belagro.com/Redmine/ruby/lib/ruby/gems/1.8/gems/rmagick-2.12.0/doc/colorize.rb.html
Based on the code in the above link, with the greyscale conversion removed, does the example below work (I don't have ruby)?
# load the greyscale image
img = Magick::Image.read('greyscale.png').first
# Colorize with a 100% blend of the orange color
colorized = img.colorize(1, 1, 1, '#A50026')
# save the colour image
colorized.write('colour.png')
Used a colour picker to get the hex of your orange colour - rgb(244,93,0) = #A50026
I have an image and would like to apply a watermark (another image) over it using Node.js. The requirement is watermark shouldn't be a solid picture (what I can do with gm library's draw()) but half transparent. Can you please advise any tool to use?
Use ImageMagick from the command line by forking a child-process
// Require our module dependencies
var exec = require('child_process').exec;
// Create command array to invoke ImageMagick composite where
// -dissolve is the amount of transparency for the watermark
// -gravity tells how to align images of varying size
// -quality is the image quality of the JPEG (not required if producing PNG)
var command = [
'composite',
'-dissolve', '50%',
'-gravity', 'center',
'-quality', 100,
'/path/to/watermark.png',
'/path/to/image.jpg',
'/path/to/save/result.jpg';
];
// Join command array by a space character and then execute command
exec(command.join(' '), function(err, stdout, stderr) {
// Do stuff with result here
});
If you need an API abstraction, there is a great module found here https://github.com/rsms/node-imagemagick
You could make watermark image half-transparent already and use it with gm:
gm('/path/to/input-image.jpg')
.draw(['image Over 0,0 0,0 /path/to/half-transparent-watermark-image.png'])
.write('/path/to/output-image.jpg', function(e){
console.log(e||'done'); // What would you like to do here?
});
I use code
gm('/path/to/input-image.jpg')
.draw(['image Over 0,0 0,0 /path/to/half-transparent-watermark-image.png'])
.write('/path/to/output-image.jpg', function(e){
console.log(e||'done'); // What would you like to do here?
});
Error: Command failed: convert: Non-conforming drawing primitive definition `/path/to/half-transparent-watermark-image.png''# draw.c / DrawImage / 3124
I want to cut a circle out of an image using rmagick.
Here's an example of what I'd like to be able to accomplish:
-->
It seems like I want to use http://studio.imagemagick.org/RMagick/doc/draw.html#circle to cut a circle, and then clip_path to mask it, but the docs aren't very clear. Would anyone be able to point me in the right direction?
require 'rmagick'
im = Magick::Image.read('walter.jpg').first
circle = Magick::Image.new 200, 200
gc = Magick::Draw.new
gc.fill 'black'
gc.circle 100, 100, 100, 1
gc.draw circle
mask = circle.blur_image(0,1).negate
mask.matte = false
im.matte = true
im.composite!(mask, Magick::CenterGravity, Magick::CopyOpacityCompositeOp)
im.write 'walter_circle.png'
This is how I would do it with Imagemagick and php:
// Canvas the same size as the final image
exec("convert -size 800x533 xc:white white.jpg");
// The mask
exec("convert -size 800x533 xc:none -draw \"fill black circle 400,265 400,50\" write_mask.png");
// Cut the whole out of the canvas
exec("composite -compose Dst_Out write_mask.png white.jpg -matte step.png");
// Put the canvas over the image and trim off excess white background
exec("convert IMG_5745.jpg step.png -composite -trim final.jpg");
You should be able to follow the process?
Cleanup tempory images afterwards - I tend to save the tempory images in a .miff format and then write a loop to delete all .miff images afterwards. Alternativly just leave them and if you use the same name for the tempory images they will be overwritten every time the code is run.