Apply XMP photo manipulation in ImageMagick - imagemagick

I want to automatically manipulate images with ImageMagick (or any other tool that can be run on an Ubuntu server or called via an API). In order to get exactly the result I want, I have tinkered with Photoshop and exported the XMP metadata to document the manipulation. It looks like this:
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.3-c007 1.136881, 2010/06/10-18:11:35 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:crs="http://ns.adobe.com/camera-raw-settings/1.0/"
crs:Version="7.0"
crs:ProcessVersion="6.7"
crs:Sharpness="38"
crs:LuminanceSmoothing="0"
crs:VignetteAmount="-17"
crs:VignetteMidpoint="32"
crs:SplitToningShadowHue="0"
crs:SplitToningShadowSaturation="0"
crs:SplitToningHighlightHue="0"
crs:SplitToningHighlightSaturation="0"
crs:SplitToningBalance="-15"
crs:ParametricShadows="-14"
crs:ParametricDarks="-16"
crs:ParametricLights="+4"
crs:ParametricHighlights="+31"
crs:ParametricShadowSplit="25"
crs:ParametricMidtoneSplit="50"
crs:ParametricHighlightSplit="75"
crs:SharpenRadius="+0.5"
crs:SharpenDetail="100"
crs:SharpenEdgeMasking="17"
crs:PostCropVignetteAmount="0"
crs:GrainAmount="24"
crs:GrainSize="2"
crs:GrainFrequency="6"
crs:LensProfileEnable="0"
crs:LensManualDistortionAmount="-2"
crs:PerspectiveVertical="0"
crs:PerspectiveHorizontal="0"
crs:PerspectiveRotate="0.0"
crs:PerspectiveScale="100"
crs:Exposure2012="-0.05"
crs:Contrast2012="0"
crs:Highlights2012="+27"
crs:Shadows2012="+18"
crs:Whites2012="+29"
crs:Blacks2012="+1"
crs:Clarity2012="+6"
crs:ToneCurveName2012="Linear"
crs:LensProfileSetup="Auto"
crs:HasSettings="True">
<crs:ToneCurvePV2012>
<rdf:Seq>
<rdf:li>0, 0</rdf:li>
<rdf:li>255, 255</rdf:li>
</rdf:Seq>
</crs:ToneCurvePV2012>
<crs:ToneCurvePV2012Red>
<rdf:Seq>
<rdf:li>0, 0</rdf:li>
<rdf:li>255, 255</rdf:li>
</rdf:Seq>
</crs:ToneCurvePV2012Red>
<crs:ToneCurvePV2012Green>
<rdf:Seq>
<rdf:li>0, 0</rdf:li>
<rdf:li>255, 255</rdf:li>
</rdf:Seq>
</crs:ToneCurvePV2012Green>
<crs:ToneCurvePV2012Blue>
<rdf:Seq>
<rdf:li>0, 0</rdf:li>
<rdf:li>255, 255</rdf:li>
</rdf:Seq>
</crs:ToneCurvePV2012Blue>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>
Now I would like to apply exactly the same manipulation with a tool that can be run server-side. Is it possible ? Can I achieve exactly the same result with ImageMagick ? Does Photoshop expose an API, or maybe a SDK allowing me to do that ?

I think it would be a pretty massive ask of ImageMagick to achieve identical results, or even close, to those achieved by Photoshop.
Adobe puts massive development effort into ACR (Camera Raw) and things like lens profiles require vast amounts of testing and management of databases of lens characteristics on different cameras which are just not part of the remit or objective of ImageMagick.
Also, ImageMagick delegates the RAW processing to UFRAW and I don't believe that supports advanced features like "Clarity" and "Luminance Smoothing".
Photoshop does expose an API which is scriptable - Adobe Photoshop Scripting in JavaScript, AppleScript and VBScript.

One way to accomplish this for RAW photos is to use the free Adobe DNG Converter (available for both Windows and macOS, but the Windows version might run with wine).
When you ask it to convert a RAW to a DNG you can have it embed a full size JPEG preview in the DNG. It will respect whatever settings are in the XMP when generating the JPEG preview. You can ask it to convert a DNG to a second DNG as a way to update the embed preview. And it works from the command line.
Then use something like ExifTool to edit the XMP metadata, and to extract the embed JPEG preview.
I've used this with reasonable success to create a barebones RAW converter:
https://github.com/ncruces/RethinkRAW

Related

Extracting images from video in JRuby-1.7.13

I want to extract images from a m4v video sent from mobile to my rails server. These images will be later used for face recognization purposes. There is a gem called "streamio-ffmpeg" that does this job nicely and easily but the problem is that it does not support JRuby-1.7.13 that I am currently using on my server. It's a big application and upgrading the JRuby version not desirable at this moment.
Can someone please suggest JRuby1.7.13 compatible alternative solutions/gems to extract the images from a video file?
From the sourcecode, it looks like streamio-ffmpeg outputs the underlying command by default :
FFMPEG.logger.info("Running transcoding...\n#{command}\n")
So all you have to do is execute :
movie.screenshot("screenshot_%d.jpg", { vframes: 50, frame_rate: '6/2' }, validate: false)
on a system where streamio-ffmpeg is installed.
You look at the output, extract the command, and use it somewhere else with :
system("ffmpeg arguments_you_extracted_from_the_logs")
without having to install streamio-ffmpeg.

open office crashes after some time giving garbled font in converted PDF

We are converting word to pdf using the openoffice(3.4.1 version) in java with JODConverter.
below is the code used.
OpenOfficeConnection connection =
new SocketOpenOfficeConnection(2100);
try
{
connection.connect();
DocumentConverter converter =
new OpenOfficeDocumentConverter(connection);
converter.convert(inputFile, outputFile);
connection.disconnect();
return "Sucess " + DestinationPath + DestinationFileName;
}
catch (Exception localException1) {
}
The problem is that after random no of days the converted PDF contains the garbled fonts.
like # # ! $ $ " % &
The only solution we have so far is to restart the server. System guys are saying the the problem is with Open Office.
We are using open office to convert the document since it converts the doc files exactly including all the formatting and table structure.
what could be the solution to this.
So OpenOffice can be a little temperamental when running on a server, especially as it isn't multi-threaded and you end up having to run a pool of OpenOffice processes - see How can I use OpenOffice in server mode as a multithreaded service?.
Added to that often the rendering is off when converting to PDF - see https://forum.openoffice.org/en/forum/viewtopic.php?f=7&t=68865 which is why you may want to consider using a conversion service to automate the conversion tasks for you ?
For complete transparency I work for Zamzar (an online file conversion service), we have recently released a developer API - https://developers.zamzar.com/ that allows you to convert between a multitude of file types, specifically applicable to you here in that we support both doc and docx to pdf with little or not loss in the way the PDF is rendered. It maybe worth a look to see if this is a better alternative to trying to run your own solution through OpenOffice on a server.

Objective C and SVG

I am receiving a SVG back from our server that I need to display. What the server is returning is:
preview = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"256\" height=\"256\" preserveAspectRatio=\"xMedYMed meet\" viewBox=\"-10756457.3242036 -5943062.39021874 1277.60796701722 1244.16676712781\">\n <path d=\"M -10756407.324203580617905 -5942993.280961670912802 L -10756388.214946510270238 -5941880.166737286373973 -10755229.716236563399434 -5941868.223451617173851 -10755244.048179365694523 -5942728.140019812621176 -10755394.533578801900148 -5942730.528676947578788 -10755396.922235935926437 -5943012.390218744985759 -10755578.460178112611175 -5943005.224247347563505 -10755671.617806335911155 -5942995.669618809595704 -10755764.775434559211135 -5943005.224247347563505 -10755845.98977711237967 -5942990.892304535955191 -10755958.256662406027317 -5943000.446933076716959 -10756166.069833055138588 -5943002.835590209811926 -10756216.231632867828012 -5942998.058275939896703 -10756261.616118412464857 -5942990.892304535955191 -10756347.607775231823325 -5943002.835590209811926 Z\" stroke-width=\"1\" fill=\"black\" stroke=\"black\">\n </path>\n</svg>";
I am looking at the library the SVGKit. I'm not exactly sure what I can do with this information. Can SVGKit load this type of data or does it need to be a local SVG file?
We want to use this SVG cause its a lot smaller then a .png and the server is returning lots of them.
Any ideas on what I can do?
According to the documentation you can load an SVG file from data which is what you have.

convert jpeg/png to tiff in java

I am using batik library for image conversion , I need to convert jpeg/png to tiff format.
Can anyone help me on how to do the conversion using batik (preferable) , because i am using the same library for other SVG conversions.
You could probably do PNG - > SVG - > TIFF conversion.
This link should point you in the right direction:
http://xmlgraphics.apache.org/batik/tools/rasterizer.html
check the "Examples of using the rasterizer task" section.
Hope this helps.

Google PageSpeed & ImageMagick JPG compression

Given a user uploaded image, I need to create various thumbnails of it for display on a website. I'm using ImageMagick and trying to make Google PageSpeed happy. Unfortunately, no matter what quality value I specify in the convert command, PageSpeed is still able to suggest compressing the image even further.
Note that http://www.imagemagick.org/script/command-line-options.php?ImageMagick=2khj9jcl1gd12mmiu4lbo9p365#quality mentions:
For the JPEG ... image formats,
quality is 1 [provides the] lowest
image quality and highest compression
....
I actually even tested compressing the image using 1 (it produced an unusable image, though) and PageSpeed still suggests that I can still optimize such image by "losslessly compressing" the image. I don't know how to compress an image any more using ImageMagick. Any suggestions?
Here's a quick way to test what I am talking about:
assert_options(ASSERT_BAIL, TRUE);
// TODO: specify valid image here
$input_filename = 'Dock.jpg';
assert(file_exists($input_filename));
$qualities = array('100', '75', '50', '25', '1');
$geometries = array('100x100', '250x250', '400x400');
foreach($qualities as $quality)
{
echo("<h1>$quality</h1>");
foreach ($geometries as $geometry)
{
$output_filename = "$geometry-$quality.jpg";
$command = "convert -units PixelsPerInch -density 72x72 -quality $quality -resize $geometry $input_filename $output_filename";
$output = array();
$return = 0;
exec($command, $output, $return);
echo('<img src="' . $output_filename . '" />');
assert(file_exists($output_filename));
assert($output === array());
assert($return === 0);
}
echo ('<br/>');
}
The JPEG may contain comments, thumbnails or metadata, which can be removed.
Sometimes it is possible to compress JPEG files more, while keeping the same quality. This is possible if the program which generated the image did not use the optimal algorithm or parameters to compress the image. By recompressing the same data, an optimizer may reduce the image size. This works by using specific Huffman tables for compression.
You may run jpegtran or jpegoptim on your created file, to reduce it further in size.
To minimize the image sizes even more, you should remove all meta data. ImageMagick can do this by adding a -strip to the commandline.
Have you also considered to put your thumbnail images as inline-d base64 encoded data into your HTML?
This can make your web page load much faster (even though the size gets a bit larger), because it saves the browser from running multiple requests for all the image files (the images) which are referenced in the HTML code.
Your HTML code for such an image would look like this:
<IMG SRC="data:image/png;base64,
iVBORw0KGgoAAAANSUhEUgAAAM4AAABJAQMAAABPZIvnAAAABGdBTUEAALGPC/xh
BQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAA
OpgAABdwnLpRPAAAAAZQTFRFAAAA/wAAG/+NIgAAAAF0Uk5TAEDm2GYAAAABYktH
RACIBR1IAAAACXBIWXMAAABIAAAASABGyWs+AAAB6ElEQVQ4y+3UQY7bIBQG4IeQ
yqYaLhANV+iyi9FwpS69iGyiLuZYpepF6A1YskC8/uCA7SgZtVI3lcoiivkIxu/9
MdH/8U+N6el2pk0oFyibWyr1Q3+PlO2NqJV+/BnRPMjcJ9zrfJ/U+zQ9oAvo+QGF
d+npPqFQn++TXElkrEpEJhAtlTBR6dNHUuzIMhFnEhxAmJDkKxlmt7ATXDDJYcaE
r4Txqtkl42VYSH+t9KrD9b5nxZeog/LWGVHprGInGWVQUTvjDWXca5KdsowqyGSc
DrZRlGlQUl4kQwpUjiSS9gI9VdECZhHFQ2I+UE2CHJQfkNxTNKCl0RkURqlLowJK
1h1p3sjc0CJD39D4BIqD7JvvpH/GAxl2/YSq9mtHSHknga7OKNOHKyEdaFC2Dh1w
9VSJemBeGuHgMuh24EynK03YM1Lr83OjUle38aVSfTblT424rl4LhdglsUag5RB5
uBJSJBIiELSzaAeIN0pUlEeZEMeClC4cBuH6mxOlgPjC3uLproUCWfy58WPN/MZR
86ghc888yNdD0Tj8eAucasl2I5LqX19I7EmEjaYjSb9R/G1SYfQA7ZBuT5H6WwDt
UAfK1BOJmh/eZnKLeKvZ/vA8qonCpj1h6djfbqvW620Tva36++MXUkNDlFREMVkA
AAAldEVYdGRhdGU6Y3JlYXRlADIwMTItMDgtMjJUMDg6Mzc6NDUrMDI6MDBTUnmt
AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDEyLTA4LTIyVDA4OjM3OjQ1KzAyOjAwIg/B
EQAAAA50RVh0bGFiZWwAImdvb2dsZSJdcbX4AAAAAElFTkSuQmCC"
ALT="google" WIDTH=214 HEIGHT=57 VSPACE=5 HSPACE=5 BORDER=0 />
And you would create the base64 encoded image data like this:
base64 -i image.jpg -o image.b64
Google performs those calculations based on it's WebP image format (https://developers.google.com/speed/webp/).
Despite giving performance gains though, it is currently supported only by chrome and opera (http://caniuse.com/webp)

Resources