How to add a background-texture image, in PHP, with imagemagick, webp with transparent background to .jpg - imagemagick

PHP, imagemagick, file format: webp with transparent background,
converting to .jpg.
How to add a background-texture ($texture='www.url-to-image.jpg';) instead of the color #222222.
This is what i have, is working, but only with a color:
$image = new Imagick($img_sourse);
$image->setImageCompression(Imagick::COMPRESSION_JPEG);
$image->setImageFormat("jpg");
$image->setImageCompressionQuality(88);
$image->setImageBackgroundColor(new ImagickPixel('#222222'));
$image = $image->flattenImages();

Related

Convert png to webp does not preserve transparency

Using the Google cwebp utility (https://developers.google.com/speed/webp/docs/cwebp) and the ImageMagick convert utility, I am unable to preserve transparency in png images when converted to webp.
Using convert I've tried using alpha-compression=0 and alpha-quality=100, without positive result. See: https://imagemagick.org/script/webp.php
The images I am working with have transparent corners for a rounded icon image.
Script being used (in Fish shell):
for file in *.png;
cwebp $file -o (basename $file .png).webp;
end;
and
for file in *.png;
convert $file (basename $file .png).webp;
end;
Never mind. It was my image editor which was not displaying the transparency properly. Transparency was still there. Now filing a bug report at https://github.com/linuxmint/pix/issues

Image resize using GraphicMagick gm with 'convert' is resulting in inconsistent image

I have been trying to resize images using node.js gm module. It did work for most of the images.But when I try to resize few images, the background color and the text in the image is overlapping.My requirement is to create images of different width's without changing background color.
gm.command('convert')
.resize(100)
.gravity('Center')
.background('none')
.extent(100)
.toBuffer('JPG', function(err, buffer) {
if (err) {
next(err);
} else {
next(null, buffer, key);
}
});
Below is the original image
After resize the image is as below
I did try removing the background and tried adding transparent('white') but this didn't give me expected output. However when I use plain convert command line tool to resize it is working as expected.But my code is using node-js gm module and is deployed in AWS Lambda
Could someone help me in resolving this.
JPG does not support transparency. Try saving your output to PNG or TIFF. You might also try ImageMagick rather than GraphicsMagick. The following works fine for me in command line ImageMagick:
convert image.png -resize 100 -background none -gravity center -extent 100 result.png

ImageMagick Command Line convert PNG to EPS with Transparency

I am trying to do a simple conversion from a transparent PNG file to EPS with transparency and currently my command looks like this:
convert "image1.png" "image1.eps"
It looks like all I am getting is a black image. Any ideas?
Thanks!
Converting a PNG to an EPS is more than just a simple format conversion. Its changing from a raster image to a vector image, so the raster image has to be "traced". The popular command line tool for doing this is potrace. With potrace installed (and its component tool mkbitmap) you could do it with something like this:
convert image1.png image1.bmp
mkbitmap image1.bmp -o image1.pgm
potrace image1.pgm -e -o image1.eps
The call to mkbitmap converts the color image to a graymap more suitable for tracing.
This will yield an eps with black lines on a white background. If you need a full color trace, inkskape is a GUI tool for doing this, and an inkscape user homebrewed a command line tool to do it, which can be found here

ImageMagick: Transparent Backgrounds for JPEG, not PNG

I'm using ImageMagick to convert PDF files to PNGs. (Lots of text, so I'd rather use PNG over JPEG.) I'm doing this on OS X, 10.8.2.
I tried using Ghostscript, then ImageMagick, as was done here and I got a gray background. I shortened it to one line, since ImageMagick can work with PDFs and tried this:
convert -background transparent -transparent white \
Background-Page01.pdf TestClearX1.png
I've tried that with PNG files and JPEG files. (And with and without -transparent white as well.)
If it's a JPEG, I can get a white background (which is probably clear, but in my viewer, I can't tell), but with a PNG, I always get a dark background. I thought about, as a test, trying to generate a BMP, then converting that to PNG, but it won't generate BMP files.
How can I get a transparent background for a PNG file?
And if that's not possible, since JPEG files are not good for text, is there a better alternative?
This isn't an answer, but the format of the comment section doesn't allow sensible formatting, so I am offering it here instead.
You alluded to the fact that Preview in OS X doesn't show transparency properly, and that is correct. To get around that, I made the following script, which overlays the files you want to view onto a checkerboard pattern like Photoshop does. I save it as preview and then use chmod +x preview on it to make it executable. Here is the script:
#!/bin/bash
################################################################################
# preview
# Preview images using OSX "open" but overlay images on top of checkerboard
# first so you can see transparency/transparent pixels, since Preview renders
# them grey :-(
################################################################################
for f in "$#"
do
base=$(basename "$f")
composite -compose Dst_Over -tile pattern:checkerboard "$f" "/tmp/$base"
open -g "/tmp/$base"
done
That enables you to do:
/.preview file1.png file2.gif
and the -g option also means Preview doesn't steal focus too :-)
So, instead of looking like this:
it looks like this:
There's two ways to export a PDF in LibreOffice, and one way does not provide any warnings. The other way provides a warning that PDF/A cannot have transparent objects. The problem is you're using PDF/A files that don't support transparent objects—this results in your PNG always having a background colour.

Python Magickwand pdf to image converting and resize the image

I need to create thumbnails of pdf files, and I am using Imagemagick to achieve that.
I have tried Pythonmagick and wand to convert the pdf to an image. However, when I try to resize the converted pdf, the resulting image becomes black.
Is there any option to set -define pdf:use-cropbox=true using python wrappers?
Is there any other method in Python to convert a pdf to a thumbnail?
The code is as follows:
import wand
img = wand.image.Image(filename="d:\\test.pdf[0]")
img.resize(160,160)
img.save(filename="d:\\test.jpg")
I found work around for this problem.
Convert pdf into image 1st and save the image. open newly saved image and and resize it.
import wand
img = wand.image.Image(filename="d:\\test.pdf[0]")
img.save(filename="d:\\temp.jpg")
img = wand.image.Image(filename="d:\\temp.jpg")
img.resize(160,160)
img.save(filename="d:\\resized_image.jpg")
I am still waiting for better answer.
I faced the same problem today. I found another solution in other post.
The reason why the image turns to black is that the background is transparent in PDF file. Since JPG file cannot recognize the alpha-channel (which record the transparent pixel information). JPG files will set those transparent pixel into black as default.
# Use the following two lines to fix this error
# img_page.background_color = Color('white')
# img_page.alpha_channel = 'remove'
with Image(filename="file.pdf",resolution= 350) as img_pdf:
num_pages = len(img_pdf.sequence)
for page, img in enumerate(img_pdf.sequence):
img_page = Image(image=img)
img_page.background_color = Color('white')
img_page.alpha_channel = 'remove'
img_page.resize(900,1200)
img_page.save(filename="file"+str(page)+".jpg")
if page == 0:
img_page.resize(500, 500)
img_page.save(filename="thumbnail.jpg")
ref: Python Wand convert PDF to PNG disable transparent (alpha_channel)
You can do it without using temporary files - if you don't depend on JPG.
The following works for me:
import wand
img=wand.image.Image(filename="/home/vagrant/tmp/wand/law.pdf[0]")
img.format='png'
img.resize(220,220)
img.save(filename="/home/vagrant/tmp/wand/law_2.png")

Resources