In a laptop mockup or a phone mockup or others any kind of mockup, I want to insert an external image is there any script PHP or javascript like my idea? I already found some site are doing same. How do I build it? Can anyone give me some idea?
My example site is http://magicmockups.com/mockup/10/
You can use Imagemagick's perspective distortion after you measure the corners in both images.
Background:
Image:
Command (Unix syntax):
convert background.png \
\( monet2.jpg -virtual-pixel none +distort perspective "0,0 317,99 265,0 540,85 265,333 594,426 0,333 342,446" \) \
-layers merge +repage monet2_background.jpg
If on Windows, remove the \ before ( and before ) and change the end of line \ to ^.
Result:
You can run this from PHP exec() or recode it in PHP Imagick syntax.
You can use PHP image processing libraries such as PHP GD or ImageMagick.
I have to write a script in linux with the identify command to extract a date from an image file and add it to the image itself this has to be done for every file in the specified directory. Anyone who could help me? Thanks a lot! I'm now on to this:
for file in $picturemap
do
identify -verbose $file > date.txt
date= date.txt grep | "date:create:"
done
its everything i know
You can use imagemagick package to draw on image files, convert them to other formats and lots of other stuff. There are huge amount of switches that can be useful, just reffer to the documentation.
Install imagemagick
sudo apt-get install imagemagick
Use convert command with draw switch.
Example:
convert test1.jpg -weight 700 -pointsize 200 -draw "gravity north fill black text 0,100 'text' " test2.jpg
this will take test1.jpg annotate text with black color in your image and write it to test.jpg.
This is the command I am running (directly from the command line, logged in as root):
/usr/bin/convert '/var/storage/files/drupal/273f09ab5f8671d3c457719c7955063f.jpg' -resize 127x127! -quality '75' '/var/storage/files/drupal/imagecache/artwork_moreart/273f09ab5f8671d3c457719c7955063f.jpg'
The result of the command is just: Segmentation fault
Version of ImageMagic: ImageMagick 6.4.3 2009-02-25
Linux version: SUSE Linux Enterprise Server 11 (x86_64)
This image does exists and I have copied it to my local computer and opened it up with no issue.
Please let me know if there is additional information you need and how to get this information.
Try it with a correct command. The ! needs backslash-escaping, first of all, otherwise it is interpreted by your shell, instead of by convert:
/usr/bin/convert \
'/var/storage/files/drupal/273f09ab5f8671d3c457719c7955063f.jpg' \
-resize 127x127\! -quality '75' \
'/var/storage/files/drupal/imagecache/artwork_moreart/273f09ab5f8671d3c457719c7955063f.jpg'
If this doesn't work, try to surround the argument with single quotes too (like you did with your other arguments:
127x127\! => '127x127\!'
The cause of your problem could also reside outside the convert binary, and be within the specific input JPEG you want process. You can try to rule this out by processing a set different input files. Start with the built-in IM test files logo:, wizard: and netscape::
convert wizard: \
-resize "127x127\!" \
127wiz.jpg
convert logo: \
-resize "127x127\!" \
127log.jpg
convert netscape: \
-resize "127x127\!" \
127net.jpg
Sorry, I cannot reproduce your problem directly here. SLES 11 with IM 6.4.3 is simply too ancient for me.
I have a SVG file that has a defined size of 16x16. When I use ImageMagick's convert program to convert it into a PNG, then I get a 16x16 pixel PNG which is way too small:
convert test.svg test.png
I need to specify the pixel size of the output PNG. -size parameter seems to be ignored, -scale parameter scales the PNG after it has been converted to PNG. The best result up to now I got by using the -density parameter:
convert -density 1200 test.svg test.png
But I'm not satisfied, because I want to specify the output size in pixels without doing math to calculate the density value. So I want to do something like this:
convert -setTheOutputSizeOfThePng 1024x1024 test.svg test.png
So what is the magic parameter I have to use here?
I haven't been able to get good results from ImageMagick in this instance, but Inkscape does a nice job of scaling an SVG on Linux and Windows:
# Inkscape v1.0+
inkscape -w 1024 -h 1024 input.svg -o output.png
# Inkscape older than v1.0
inkscape -z -w 1024 -h 1024 input.svg -e output.png
Note that you can omit one of the width/height parameters to have the other parameter scaled automatically based on the input image dimensions.
Here's the result of scaling a 16x16 SVG to a 200x200 PNG using this command:
Try svgexport:
svgexport input.svg output.png 64x
svgexport input.svg output.png 1024:1024
svgexport is a simple cross-platform command line tool that I have made for exporting svg files to jpg and png, see here for more options. To install svgexport install npm, then run:
npm install svgexport -g
Edit: If you find an issue with the library, please submit it on GitHub, thanks!
This is not perfect but it does the job.
convert -density 1200 -resize 200x200 source.svg target.png
Basically it increases the DPI high enough (just use an educated/safe guess) that resizing is done with adequate quality. I was trying to find a proper solution to this but after a while decided this was good enough for my current need.
Note: Use 200x200! to force the given resolution
Inkscape doesn't seem to work when svg units are not px (e.g. cm). I got a blank image. Maybe, it could be fixed by twiddling the dpi, but it was too troublesome.
Svgexport is a node.js program and so not generally useful.
Imagemagick's convert works ok with:
convert -background none -size 1024x1024 infile.svg outfile.png
If you use -resize, the image is fuzzy and the file is much larger.
BEST
rsvg-convert -w 1024 -h 1024 infile.svg -o outfile.png
It is fastest, has the fewest dependencies, and the output is about 30% smaller than convert. Install librsvg2-bin to get it:
sudo apt install -y librsvg2-bin
There does not appear to be a man page but you can type:
rsvg-convert --help
to get some assistance. Simple is good.
If you are on MacOS X and having problems with Imagemagick's convert, you might try reinstalling it with RSVG lib.
Using HomeBrew:
brew remove imagemagick
brew install imagemagick --with-librsvg
Verify that it's delegating correctly:
$ convert -version
Version: ImageMagick 6.8.9-8 Q16 x86_64 2014-12-17 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib cairo fontconfig freetype jng jpeg lcms ltdl lzma png rsvg tiff xml zlib
It should display rsvg.
After following the steps in Jose Alban's answer, I was able to get ImageMagick to work just fine using the following command:
convert -density 1536 -background none -resize 100x100 input.svg output-100.png
The number 1536 comes from a ballpark estimate of density, see this answer for more information.
In order to rescale the image, the option -density should be used. As far as I know the standard density is 72 and maps the size 1:1. If you want the output png to be twice as big as the original svg, set the density to 72*2=144:
convert -density 144 source.svg target.png
In ImageMagick, one gets a better SVG rendering if one uses Inkscape or RSVG with ImageMagick than its own internal MSVG/XML rendered. RSVG is a delegate that needs to be installed with ImageMagick. If Inkscape is installed on the system, ImageMagick will use it automatically. I use Inkscape in ImageMagick below.
There is no "magic" parameter that will do what you want.
But, one can compute very simply the exact density needed to render the output.
Here is a small 50x50 button when rendered at the default density of 96:
convert button.svg button1.png
Suppose we want the output to be 500. The input is 50 at default density of 96 (older versions of Inkscape may be using 92). So you can compute the needed density in proportion to the ratios of the dimensions and the densities.
512/50 = X/96
X = 96*512/50 = 983
convert -density 983 button.svg button2.png
In ImageMagick 7, you can do the computation in-line as follows:
magick -density "%[fx:96*512/50]" button.svg button3.png
or
in_size=50
in_density=96
out_size=512
magick -density "%[fx:$in_density*$out_size/$in_size]" button.svg button3.png
On macOS using brew, using librsvg directly works well
brew install librsvg
rsvg-convert test.svg -o test.png
Many options are available via rsvg-convert --help
For simple SVG to PNG conversion I found cairosvg (https://cairosvg.org/) performs better than ImageMagick. Steps for install and running on all SVG files in your directory.
pip3 install cairosvg
Open a python shell in the directory which contains your .svg files and run:
import os
import cairosvg
for file in os.listdir('.'):
name = file.split('.svg')[0]
cairosvg.svg2png(url=name+'.svg',write_to=name+'.png')
This will also ensure you don't overwrite your original .svg files, but will keep the same name. You can then move all your .png files to another directory with:
$ mv *.png [new directory]
why don't you give a try to inkscape command line, this is my bat file to convert all svg in this dir to png:
FOR %%x IN (*.svg) DO C:\Ink\App\Inkscape\inkscape.exe %%x -z --export-dpi=500 --export-area-drawing --export-png="%%~nx.png"
This is what worked for me and would be the easiest to run.
find . -type f -name "*.svg" -exec bash -c 'rsvg-convert -h 1000 $0 > $0.png' {} \;
rename 's/svg\.png/png/' *
This will loop all the files in your current folder and sub folder and look for .svg files and will convert it to png with transparent background.
Make sure you have installed the librsvg and rename util
brew install librsvg
brew install rename
Transparent background, exported at target height/size using ImageMagick 7:
magick -background none -size x1080 in.svg out.png
One-liner mass converter:
for i in *svg; do magick -background none -size x1080 "$i" "${i%svg}png"; done
I came to this post - but I just wanted to do the conversion by batch and quick without the usage of any parameters (due to several files with different sizes).
rsvg drawing.svg drawing.png
For me the requirements were probably a bit easier than for the original author. (Wanted to use SVGs in MS PowerPoint, but it doesn't allow)
Without librsvg, you may get a black png/jpeg image. We have to install librsvg to convert svg file with imagemagick.
Ubuntu
sudo apt-get install imagemagick librsvg
convert -density 1200 test.svg test.png
MacOS
brew install imagemagick librsvg
convert -density 1200 test.svg test.png
One thing that just bit me was setting the -density AFTER the input file name. That didn't work. Moving it to the first option in convert (before anything else) made it work (for me, YMMV, etc).
On Linux with Inkscape 1.0 to convert from svg to png need to use
inkscape -w 1024 -h 1024 input.svg --export-file output.png
not
inkscape -w 1024 -h 1024 input.svg --export-filename output.png
I've solved this issue through changing the width and height attributes of the <svg> tag to match my intended output size and then converting it using ImageMagick. Works like a charm.
Here's my Python code, a function that will return the JPG file's content:
import gzip, re, os
from ynlib.files import ReadFromFile, WriteToFile
from ynlib.system import Execute
from xml.dom.minidom import parse, parseString
def SVGToJPGInMemory(svgPath, newWidth, backgroundColor):
tempPath = os.path.join(self.rootFolder, 'data')
fileNameRoot = 'temp_' + str(image.getID())
if svgPath.lower().endswith('svgz'):
svg = gzip.open(svgPath, 'rb').read()
else:
svg = ReadFromFile(svgPath)
xmldoc = parseString(svg)
width = float(xmldoc.getElementsByTagName("svg")[0].attributes['width'].value.split('px')[0])
height = float(xmldoc.getElementsByTagName("svg")[0].attributes['height'].value.split('px')[0])
newHeight = int(newWidth / width * height)
xmldoc.getElementsByTagName("svg")[0].attributes['width'].value = '%spx' % newWidth
xmldoc.getElementsByTagName("svg")[0].attributes['height'].value = '%spx' % newHeight
WriteToFile(os.path.join(tempPath, fileNameRoot + '.svg'), xmldoc.toxml())
Execute('convert -background "%s" %s %s' % (backgroundColor, os.path.join(tempPath, fileNameRoot + '.svg'), os.path.join(tempPath, fileNameRoot + '.jpg')))
jpg = open(os.path.join(tempPath, fileNameRoot + '.jpg'), 'rb').read()
os.remove(os.path.join(tempPath, fileNameRoot + '.jpg'))
os.remove(os.path.join(tempPath, fileNameRoot + '.svg'))
return jpg
The top answer by #808sound did not work for me. I wanted to resize
and got
So instead I opened up Inkscape, then went to File, Export as PNG fileand a GUI box popped up that allowed me to set the exact dimensions I needed.
Version on Ubuntu 16.04 Linux:
Inkscape 0.91 (September 2016)
(This image is from Kenney.nl's asset packs by the way)
I was getting "low poly" curves using the general approach of increasing the density. So I decided to dig a little deeper and solve that problem as it seemed to be a side effect of this approach and I think it has to do with the original density or dpi.
We have seen 72 in this answer and 96 in this answer being suggested as the default density of an image, but which one? what if mine is different?
ImageMagick has a way to sort that out:
identify -verbose test.svg
this will put out a lot of metadata about the image file, including:
Image:
Filename: test.svg
Format: SVG (Scalable Vector Graphics)
Mime type: image/svg+xml
Class: ...
Geometry: ...
Resolution: 37.79x37.79
Print size: ...
Units: PixelsPerCentimeter
# and a whole lot MORE ...
for a more concise query you can try:
identify -format "%x x %y %U" test.svg
=> 37.789999999999999147 x 37.789999999999999147 PixelsPerCentimeter
as suggested by this forum post and modified with this documentation
Now we know the current density of the image but may need to convert it to the correct units for conversion or mogrifying (PixelsPerInch or dpi)
this is a simple calculations of PixelsPerCentimeter x 2.54
37.789999999999999147 x 2.54 = 95.9866 ~> 96
if you prefer a chart or online calculator for this you can try https://www.pixelto.net/cm-to-px-converter.
now that we have the right original density converted to dpi, the rest of the logic stated in the above answers falls into place and the svg file can be scaled to a better "resolution" by multiplying the original density.
the original density was far too pixelated as a png for me, so in my case 5x the original density or -density 480 was good enough for me. Remember that this resizes the image as well and you will need to adjust for that when using / implementing the image as compared to the original svg.
NOTE: I did try the Inkscape approaches as well and also had the pixelation problem, but had already seen an improvement with the density approach so I decided to dig into that deeper. The output of the Inkscape attempt however gave me the idea, which you can also use for determining the dpi, but that is a lot to install just to get something you can already get with ImageMagick
Area 0:0:20.75:17 exported to 21 x 17 pixels (96 dpi)
How to make Times working for printing under linux?
I have debian wheezy linux, ghostscript, cups, mscorefonts installed.
But when i do print, i get Times too wide, comparing to windows one -- letter spacing are too wide.
Any way to fix that problem?
Printing done from same Java applet and on Win and on Lin.
Postscript from Lin variant use Times fonts, postscript from Win variant uses TimesNewRomanPSMT font.
Just replacement font name changes it, but not changes anything in output.
=================
Debian Wheezy, Debian Squeeze, Ubuntu Natty checked as linux.
Most of checks was in Debian Wheezy.
ghostscript:
Installed: 9.02~dfsg-2
sun-java6-jre:
Installed: 6.26-1
cups-pdf printer.
PPD is PDF.ppd:
*PCFileName: "CUPS-PDF.PPD"
*Manufacturer: "Generic"
*Product: "(CUPS v1.1)"
*ModelName: "Generic CUPS-PDF Printer"
*ShortNickName: "Generic CUPS-PDF Printer"
*NickName: "Generic CUPS-PDF Printer"
*1284DeviceID: "MFG:Generic;MDL:CUPS-PDF Printer;DES:Generic CUPS-PDF Printer;CLS:PRINTER;CMD:POSTSCRIPT;"
Print result Comparsion: http://piccy.info/code2/1652248/4b2c3b10f5316f9836496af5501892d1/
I DO have Times New Roman font on linux system! PDF for windows was generated on linux with linux ghostscript from postscript source generated on windows machine.
For example, take a look into right upper corner, where 0401060 written.
Windows postscript code:
%%IncludeResource: font TimesNewRomanPS-BoldMT
F /F1 0 /256 T /TimesNewRomanPS-BoldMT mF
/F1S53 F1 [83 0 0 -83 0 0 ] mFS
F1S53 Ji
4292 333 M (0401060)[42 42 42 42 42 42 0]xS
N 367 367 M 1192 367 I K
N 1667 367 M 2492 367 I K
51282 VM?
linux postscript code:
10.0 29 F
<303430313036> 37.44 526.0 52.0 S
10.0 29 F
<30> 6.24 541.0 62.0 S
N
as you can see, it selects font #29 of size 10.0. Font #29 is
/Times-Bold ISOF
and, worst thing, it already writes two lines -- so problem are somewhere in java<=>cups connector.
==================
"Same Java Applet" is internet-bank application iBank2.
"Times" is substituted by Ghostscript to Nimbus, not to TimesNewRoman:
./Init/Fontmap.GS:/Times-Roman /NimbusRomNo9L-Regu ;
./Init/Fontmap.GS:/Times-Italic /NimbusRomNo9L-ReguItal ;
./Init/Fontmap.GS:/Times-Bold /NimbusRomNo9L-Medi ;
./Init/Fontmap.GS:/Times-BoldItalic /NimbusRomNo9L-MediItal ;
./Init/Fontmap.GS:/TimesNewRoman /TimesNewRomanPSMT ;
./Init/Fontmap.GS:/TimesNewRoman,Bold /TimesNewRomanPS-BoldMT ;
./Init/Fontmap.GS:/TimesNewRoman,Italic /TimesNewRomanPS-ItalicMT ;
./Init/Fontmap.GS:/TimesNewRoman,BoldItalic /TimesNewRomanPS-BoldItalicMT ;
(BTW, are you using Ghostscript on Windows at all, or is your printing there going through a native printer driver?)
On windows i'm print onto PostScript native driver to .ps file.
So it is NOT a Ghostscript problem per se... but it maybe originating from different Java versions + configurations on your Win/Lin systems.
It looks like problem in java on printing, but that doesn't depends on java version -- both have latest java6 installed.
That PostScript most likely generated by your Java applet, and Ghostscript is only the consumer of it when it goes through the printing process.
Normally, i just want to make sure it uses TimesNewRoman font for Times one, not Nimbus.
And i have failed to make this.
ISOF macro generated by printing is:
/ISOF {
dup findfont dup length 1 add dict begin {
1 index /FID eq {pop pop} {D} ifelse
} forall /Encoding ISOLatin1Encoding D
currentdict end definefont
} BD
Here is cut of start files, and generated resulting PDF: http://datacompboy.ru/u/smpl.tar.bz2
If this is so, then copy the Windows fontfile to Linux.
it are already copy of windows file. msttcorefonts are identical to one, distributed with windows.
Since in generated postscript file already 0401060 split to two lines, that means, that java applet are while printing found that font too wide, and split upon generating... So question is -- how to substitute Times font in system so, that java printing will find TimesNewRoman instead of Nimbus, and generate correct output?
From what I see in the screenshot, your Win <--> Lin printing differences...
...do NOT originate in Times <--> TimesNewRomanPSMT differences,
...but rather come from [SomeTimes] <--> [SomeTimesBold] differences in the 2 PostScript output(s)
that is consumed by each printer queue (which on Linux very likely involves a Ghostscript installation). (BTW, are you using Ghostscript on Windows at all, or is your printing there going through a native printer driver?)
So it is NOT a Ghostscript problem per se... but it maybe originating from different Java versions + configurations on your Win/Lin systems.
The fact that your Linux PostScript code seems to make use of the /Times-Bold (ISOF????) font is outside of Ghostscript's responsibility. That PostScript most likely generated by your Java applet, and Ghostscript is only the consumer of it when it goes through the printing process.
It looks to me that this ominous ISOF you mentioned is not part of the fontname, but a PostScript procedure that must be pre-defined elsewhere in the PostScript file and is applied to the /Times-Bold font. It is probably a procedure which re-encodes the original font to ISOLatin1Encoding...
You say you have access to both font files (TimesNewRomanPS-BoldMT on Windows and Times-Bold on Linux). If this is so, then copy the Windows fontfile to Linux. Then, to verify the visual differences between the two fonts, run these two commands on each of the fontfiles:
fntsample \
-f /path/to/Times-fontfile.suffix \
-o Times-fontfile.suffix.pdf \
-l \
> Times-fontfile.suffix.txt
and then
pdfoutline \
Times-fontfile.suffix.pdf \
Times-fontfile.suffix.txt \
Times-fontfile-sample.pdf
The resulting PDF(s), Times-fontfile-sample.pdf, will represent a tabular sample of each glyph contained in the fontfiles, and these will be mapped to the respective Unicode codepoints sections.
You can use these PDFs to reveal even minimal visual discrepancies between the two fonts (but I bet your differences will be rather glaring).
In case you don't have installed pdfoutline and fntsample in your Debian, just run sudo apt-get install fntsample...
Update 2 (taking into account the updated problem description):
datacompboy has now provided a tarball containing these 4 files:
-rw-r--r-- datacompboy/datacompboy 37722 2011-06-22 08:54 smpl/linout.ps
-rw-r--r-- datacompboy/datacompboy 15324 2011-06-22 08:54 smpl/linout.pdf
-rw-r--r-- datacompboy/datacompboy 54422 2011-06-22 08:57 smpl/winout.pdf
-rw-r--r-- datacompboy/datacompboy 99099 2011-06-22 08:56 smpl/winout.ps
With these files, it should be very easy to pinpoint the cause of the problem. If datacompboy can run the Windows-generated PS file on a Linux Ghostscript, like this:
gs winout.ps
and if it renders OK (i.e.: the same as winout.pdf), then there is no problem with the GS font mapping, but a problem with the actual file differences in winout/linout.ps. From there, it should be quite easy to continue the analysis.
Unfortunately, right now I cannot run the test myself.
Update 3:
datacompboy's PDF files linout.pdf and winout.pdf have one huge difference: the Linux version doesn't have the font embedded, while the Windows one has... The consequence is that any posterior consumer of linout.pdf will produce fairly arbitrary results when displaying, printing, converting or processing this file with regard to the font.
So here is another test that I can think of. It checks how much the Linux versions of the fonts used for /Times-Bold (which is substituted by Ghostscript with the real /NimbusRomNo9L-Medi) and /TimesNewRomanPS-BoldMT` do differ in their font metrics.
Create three different PDFs with these Ghostscript commandlines:
a.pdf:
gs \
-o a.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-c "100 700 moveto \
/TimesNewRoman,Bold findfont \
12 scalefont \
setfont \
(0401060 0401060 0401060 0401060) show \
showpage"
b.pdf:
gs \
-o b.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-c "100 700 moveto \
/TimesNewRomanPS-BoldMT findfont \
12 scalefont \
setfont \
(0401060 0401060 0401060 0401060) show \
showpage"
c.pdf:
gs \
-o c.pdf \
-sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-c "100 700 moveto \
/Times-Bold findfont \
12 scalefont \
setfont \
(0401060 0401060 0401060 0401060) show \
showpage"
The -dPDFSETTINGS=/prepress parameter should enforce the font embedding into output PDFs. (This is important, otherwise the viewer could use an arbitrary replacement font for displaying the PDF.)
What follows the -c parameter is a little PostScript snippet that provides content for the PDF page.
Files 'a.pdf' and 'b.pdf' should not differ. They only test if the font aliasing between /TimesNewRoman,Bold and /TimesNewRomanPS-BoldMT do indeed work as expectd.
File 'c.pdf' could show slight differences in comparison to a.pdf and b.pdf in the order of a few pixel here and there, but NOT in the tracking of the tested string.
If this test goes as predicted, the different fontfiles, the Fontmap.GS and Ghostscript itself all are OK. Then the problem is only with the way the Linux Java applet produces its output (PS or PDF).