Skip to content

Commit

Permalink
Windows linux translation (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan-DowlingSoka authored Feb 3, 2023
1 parent e8d2084 commit 80f7b21
Show file tree
Hide file tree
Showing 43 changed files with 368 additions and 232 deletions.
3 changes: 1 addition & 2 deletions assets/bootstrap.bundle.min.js

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions assets/cli-translate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
var imagemagick_cli_lists = null;

function addSelectOptions(node)
{
var selectCliLanguageNode = document.createElement("select");
selectCliLanguageNode.className += "btn text-dark bg-light mx-4 cli-select-button";
selectCliLanguageNode.onchange = function(){setCliChanged(this)};
selectCliLanguageNode.title = "Change Operating System Syntax";
var selectCliLanguageOptions = ["Linux","Windows","Batch File"];

for(let option of selectCliLanguageOptions){
var optionNode = document.createElement("option");
optionNode.text=option;
selectCliLanguageNode.appendChild(optionNode);
}
node.after(selectCliLanguageNode);
return selectCliLanguageNode;
}

const imagemagick_linux_to_windows_replacements = new Map([
[/\\\s*\n/gm, "^\n"], //replace newlines with ^\n
[/\s?\\(\(|\))\s?/gm, " $1 "], // unesecape parens, add space on either side to ensure compatibility "word\)" is valid in linux in windows "word)" is not.
[/\\!/gm,"!"], // unescape exclamation point.
[/'/gm, "\""], //single quote to double quote, breaks on nested quotes.
[/\&|\||\<|\>/gm, "\\$&"], //Escape &,|,<,> - note: appears unused.
]);

const imagemagick_linux_to_windows_bat_replacements = new Map([
[/%/gm, "%%"], //Double up % signs. Needed for bat files, but not for CMD.
[/^\s*#/gm, "::"], //Replace UNIX comment # with two colons. No support for inline comments.
])

function translateLinuxToWindows(node) {
imagemagick_linux_to_windows_replacements.forEach(function(value,key){
node.innerHTML = node.innerHTML.replaceAll(key,value);
});
}

function translateWindowsToBatch(node) {
imagemagick_linux_to_windows_bat_replacements.forEach(function(value,key){
node.innerHTML = node.innerHTML.replaceAll(key,value);
});
}

function addLinuxWindowsCLIToggle(node) {
var copyNode = node.cloneNode(true);
copyNode.classList.add("cli-windows");
copyNode.style.display = "none";
translateLinuxToWindows(copyNode);
var batchNode = copyNode.cloneNode(true);
batchNode.classList.add("cli-batch");
batchNode.style.display = "none";
translateWindowsToBatch(batchNode);
if(batchNode.innerHTML == node.innerHTML) // No change, ignore.
{
copyNode.remove();
return [];
}

node.classList.add("cli-linux");
node.after(copyNode);
copyNode.after(batchNode);
return [copyNode,batchNode];
}

function addCliTranslations() {
var pres = document.querySelectorAll('pre.cli');
var cliWindowsList = [];
var cliBatchList = [];
var cliLinuxList = [];
var cliSelectList = [];
for (let pre of pres) {
var samp = pre.querySelector("samp");
if(samp != null) {
var translated = addLinuxWindowsCLIToggle(samp);
if(translated.length == 2)
{
cliLinuxList.push(samp);
cliWindowsList.push(translated[0]);
cliBatchList.push(translated[1]);
cliSelectList.push(addSelectOptions(pre))
}
}
}

return {"windows":cliWindowsList, "linux":cliLinuxList, "batch": cliBatchList, "select":cliSelectList};
}

function setCliLanguage(language){
if( imagemagick_cli_lists == null) {
imagemagick_cli_lists = addCliTranslations();
}

var display_windows = language == "Windows" ? "inherit" : "none";
var display_linux = language == "Linux" ? "inherit" : "none";
var display_batch = language == "Batch File" ? "inherit" : "none";
for( let node of imagemagick_cli_lists["windows"])
{
node.style.display = display_windows;
}
for( let node of imagemagick_cli_lists["linux"])
{
node.style.display = display_linux;
}
for( let node of imagemagick_cli_lists["batch"])
{
node.style.display = display_batch;
}
for( let node of imagemagick_cli_lists["select"] )
{
node.value = language;
}
}

function setCliChanged(selectNode){
setCliLanguage(selectNode.value);
}

if( imagemagick_cli_lists == null) {
imagemagick_cli_lists = addCliTranslations();
}
1 change: 1 addition & 0 deletions assets/cli-translate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/magick-js.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
header('Expires: ' . gmdate('D, d M Y H:i:s',time()+604800) . ' GMT');
header("Content-type: text/javascript; charset=utf-8");
readfile('bootstrap.bundle.min.js');
readfile('cli-translate.min.js');
ob_end_flush();
?>
10 changes: 10 additions & 0 deletions assets/magick-template.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,13 @@ a.anchor {
max-height: 340px;
overflow-y: scroll;
}

.cli-select-button{
font-size:.75rem;
float:right;
clear:both;
position:relative;
top:-18px;
height:22px;
padding:0px;
}
8 changes: 4 additions & 4 deletions include/advanced-linux-installation.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,18 +400,18 @@

<p>To confirm your installation of the ImageMagick distribution was successful, ensure that the installation directory is in your executable search path and type:</p>

<pre class="bg-light text-dark mx-4"><samp>magick logo: logo.gif
<pre class="bg-light text-dark mx-4 cli"><samp>magick logo: logo.gif
identify logo.gif</samp></pre>

<p>The ImageMagick logo is displayed on your X11 display.</p>

<p>To verify the ImageMagick build configuration, type:</p>

<pre class="bg-light text-dark mx-4"><samp>magick identify -list configure</samp></pre>
<pre class="bg-light text-dark mx-4 cli"><samp>magick identify -list configure</samp></pre>

<p>To list which image formats are supported , type:</p>

<pre class="bg-light text-dark mx-4"><samp>magick identify -list format </samp></pre>
<pre class="bg-light text-dark mx-4 cli"><samp>magick identify -list format </samp></pre>

<p>For a more comprehensive test, you run the ImageMagick test suite by typing:</p>

Expand Down Expand Up @@ -519,7 +519,7 @@

<p>Now reconfigure, rebuild, and reinstall ImageMagick. To verify JPEG is now properly supported within ImageMagick, use this command:</p>

<pre class="bg-light text-dark mx-4"><samp>magick identify -list format </samp></pre>
<pre class="bg-light text-dark mx-4 cli"><samp>magick identify -list format </samp></pre>

<p>You should see a mode of rw- associated with the JPEG tag. This mode means the image can be read or written and can only support one image per image file.</p>

Expand Down
4 changes: 2 additions & 2 deletions include/animate.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

<p>We list a few examples of the <samp>animate</samp> command here to illustrate its usefulness and ease of use. To get started, lets animate an image sequence in the GIF format:</p>

<pre class="bg-light text-dark mx-4"><samp>magick animate movie.gif </samp></pre>
<pre class="bg-light text-dark mx-4 cli"><samp>magick animate movie.gif </samp></pre>

<p>To animate a directory of JPEG images, use:</p>

<pre class="bg-light text-dark mx-4"><samp>magick animate *.jpg </samp></pre>
<pre class="bg-light text-dark mx-4 cli"><samp>magick animate *.jpg </samp></pre>

<p>You can find additional examples of using <samp>animate</samp> in <a href="https://imagemagick.org/Usage/basics/#animate">Examples of ImageMagick Usage</a>.</p>

Expand Down
26 changes: 13 additions & 13 deletions include/architecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@

<h2>Distributed Pixel Cache</h2>
<p>A distributed pixel cache is an extension of the traditional pixel cache available on a single host. The distributed pixel cache may span multiple servers so that it can grow in size and transactional capacity to support very large images. Start up the pixel cache server on one or more machines. When you read or operate on an image and the local pixel cache resources are exhausted, ImageMagick contacts one or more of these remote pixel servers to store or retrieve pixels. The distributed pixel cache relies on network bandwidth to marshal pixels to and from the remote server. As such, it will likely be significantly slower than a pixel cache utilizing local storage (e.g. memory, disk, etc.).</p>
<pre class="bg-light text-dark mx-4"><samp>magick -distribute-cache 6668 &amp; // start on 192.168.100.50
<pre class="bg-light text-dark mx-4 cli"><samp>magick -distribute-cache 6668 &amp; // start on 192.168.100.50
magick -define registry:cache:hosts=192.168.100.50:6668 myimage.jpg -sharpen 5x2 mimage.png
</samp></pre>

Expand Down Expand Up @@ -448,13 +448,13 @@
<p>A great majority of image formats and algorithms restrict themselves to a fixed range of pixel values from 0 to some maximum value, for example, the Q16 version of ImageMagick permit intensities from 0 to 65535. High dynamic-range imaging (HDRI), however, permits a far greater dynamic range of exposures (i.e. a large difference between light and dark areas) than standard digital imaging techniques. HDRI accurately represents the wide range of intensity levels found in real scenes ranging from the brightest direct sunlight to the deepest darkest shadows. Enable <a href="<?php echo $_SESSION['RelativePath']?>/../script/high-dynamic-range.php">HDRI</a> at ImageMagick build time to deal with high dynamic-range images, but be mindful that each pixel component is a 32-bit floating point value. In addition, pixel values are not clamped by default so some algorithms may have unexpected results due to out-of-band pixel values than the non-HDRI version.</p>

<p>If you are dealing with large images, make sure the pixel cache is written to a disk area with plenty of free space. Under Linux, this is typically <samp>/tmp</samp> and for Windows, <samp>c:/temp</samp>. You can tell ImageMagick to write the pixel cache to an alternate location and conserve memory with these options:</p>
<pre class="bg-light text-dark mx-4"><samp>magick -limit memory 2GB -limit map 4GB -define registry:temporary-path=/data/tmp ...
<pre class="bg-light text-dark mx-4 cli"><samp>magick -limit memory 2GB -limit map 4GB -define registry:temporary-path=/data/tmp ...
</samp></pre>

<p>Set global resource limits for your environment in the <samp>policy.xml</samp> configuration file.</p>

<p>If you plan on processing the same image many times, consider the MPC format. Reading a MPC image has near-zero overhead because its in the native pixel cache format eliminating the need for decoding the image pixels. Here is an example:</p>
<pre class="bg-light text-dark mx-4"><samp>magick image.tif image.mpc
<pre class="bg-light text-dark mx-4 cli"><samp>magick image.tif image.mpc
magick image.mpc -crop 100x100+0+0 +repage 1.png
magick image.mpc -crop 100x100+100+0 +repage 2.png
magick image.mpc -crop 100x100+200+0 +repage 3.png
Expand Down Expand Up @@ -529,30 +529,30 @@

<h2><a class="anchor" id="tera-pixel"></a>Large Image Support</h2>
<p>ImageMagick can read, process, or write mega-, giga-, or tera-pixel image sizes. An image width or height can range from 1 to 2 giga-pixels on a 32 bit OS (up to 2147483647 rows/columns) and up to 9 exa-pixels on a 64-bit OS (up to 9223372036854775807 rows/columns). Note, that some image formats have restrictions on image size. For example, Photoshop images are limited to 300,000 pixels for width or height. Here we resize an image to a quarter million pixels square:</p>
<pre class="bg-light text-dark mx-4"><samp>magick logo: -resize 250000x250000 logo.miff
<pre class="bg-light text-dark mx-4 cli"><samp>magick logo: -resize 250000x250000 logo.miff
</samp></pre>

<p>For large images, memory resources will likely be exhausted and ImageMagick will instead create a pixel cache on disk. Make sure you have plenty of temporary disk space. If your default temporary disk partition is too small, tell ImageMagick to use another partition with plenty of free space. For example:</p>
<pre class="bg-light text-dark mx-4"><samp>magick -define registry:temporary-path=/data/tmp logo: \ <br/> -resize 250000x250000 logo.miff
<pre class="bg-light text-dark mx-4 cli"><samp>magick -define registry:temporary-path=/data/tmp logo: \ <br/> -resize 250000x250000 logo.miff
</samp></pre>

<p>To ensure large images do not consume all the memory on your system, force the image pixels to memory-mapped disk with resource limits:</p>
<pre class="bg-light text-dark mx-4"><samp>magick -define registry:temporary-path=/data/tmp -limit memory 16mb \
<pre class="bg-light text-dark mx-4 cli"><samp>magick -define registry:temporary-path=/data/tmp -limit memory 16mb \
logo: -resize 250000x250000 logo.miff
</samp></pre>

<p>Here we force all image pixels to disk:</p>
<pre class="bg-light text-dark mx-4"><samp>magick -define registry:temporary-path=/data/tmp -limit area 0 \
<pre class="bg-light text-dark mx-4 cli"><samp>magick -define registry:temporary-path=/data/tmp -limit area 0 \
logo: -resize 250000x250000 logo.miff
</samp></pre>

<p>Caching pixels to disk is about 1000 times slower than memory. Expect long run times when processing large images on disk with ImageMagick. You can monitor progress with this command:</p>
<pre class="bg-light text-dark mx-4"><samp>magick -monitor -limit memory 2GiB -limit map 4GiB -define registry:temporary-path=/data/tmp \
<pre class="bg-light text-dark mx-4 cli"><samp>magick -monitor -limit memory 2GiB -limit map 4GiB -define registry:temporary-path=/data/tmp \
logo: -resize 250000x250000 logo.miff
</samp></pre>

<p>For really large images, or if there is limited resources on your host, you can utilize a distributed pixel cache on one or more remote hosts:</p>
<pre class="bg-light text-dark mx-4"><samp>magick -distribute-cache 6668 &amp; // start on 192.168.100.50
<pre class="bg-light text-dark mx-4 cli"><samp>magick -distribute-cache 6668 &amp; // start on 192.168.100.50
magick -distribute-cache 6668 &amp; // start on 192.168.100.51
magick -limit memory 2mb -limit map 2mb -limit disk 2gb \
-define registry:cache:hosts=192.168.100.50:6668,192.168.100.51:6668 \
Expand Down Expand Up @@ -726,13 +726,13 @@
<p>ImageMagick includes support for heterogeneous distributed processing with the <a href="http://en.wikipedia.org/wiki/OpenCL">OpenCL</a> framework. OpenCL kernels within ImageMagick permit image processing algorithms to execute across heterogeneous platforms consisting of CPUs, GPUs, and other processors. Depending on your platform, speed-ups can be an order of magnitude faster than the traditional single CPU.</p>

<p>First verify that your version of ImageMagick includes support for the OpenCL feature:</p>
<pre class="bg-light text-dark mx-4"><samp>magick identify -version
<pre class="bg-light text-dark mx-4 cli"><samp>magick identify -version
Features: DPC Cipher Modules OpenCL OpenMP(4.5)
</samp></pre>

<p>If so, run this command to realize a significant speed-up for image convolution:</p>

<pre class="bg-light text-dark mx-4"><samp>magick image.png -convolve '-1, -1, -1, -1, 9, -1, -1, -1, -1' convolve.png
<pre class="bg-light text-dark mx-4 cli"><samp>magick image.png -convolve '-1, -1, -1, -1, 9, -1, -1, -1, -1' convolve.png
</samp></pre>

<p>If an accelerator is not available or if the accelerator fails to respond, ImageMagick reverts to the non-accelerated convolution algorithm.</p>
Expand Down Expand Up @@ -1226,7 +1226,7 @@
}</samp></pre>

<p>To invoke the custom coder from the command line, use these commands:</p>
<pre class="bg-light text-dark mx-4"><samp>magick logo: logo.mgk
<pre class="bg-light text-dark mx-4 cli"><samp>magick logo: logo.mgk
display logo.mgk
</samp></pre>

Expand Down Expand Up @@ -1491,7 +1491,7 @@

<p>To invoke the custom filter from the command line, use this command:</p>

<pre class="bg-light text-dark mx-4"><samp>magick logo: -process \"analyze\" -verbose info:
<pre class="bg-light text-dark mx-4 cli"><samp>magick logo: -process \"analyze\" -verbose info:
Image: logo:
Format: LOGO (ImageMagick Logo)
Class: PseudoClass
Expand Down
6 changes: 3 additions & 3 deletions include/cipher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

<p>Use the <a href="<?php echo $_SESSION['RelativePath']?>/../script/command-line-options.php#encipher">-encipher</a> option to scramble your image so that it is unrecognizable. The option requires a filename that contains your passphrase. In this example we scramble an image and save it in the PNG format:</p>

<pre class="bg-light text-dark mx-4"><samp>magick rose.jpg -encipher passphrase.txt rose.png </samp></pre>
<pre class="bg-light text-dark mx-4 cli"><samp>magick rose.jpg -encipher passphrase.txt rose.png </samp></pre>

<p>Here we encipher an image using another image as the passphrase:</p>

<pre class="bg-light text-dark mx-4"><samp>magick rose.jpg -encipher smiley.gif rose.png </samp></pre>
<pre class="bg-light text-dark mx-4 cli"><samp>magick rose.jpg -encipher smiley.gif rose.png </samp></pre>

<h2><a class="anchor" id="decipher"></a>Decipher an Image</h2>

<p>Use the <a href="<?php echo $_SESSION['RelativePath']?>/../script/command-line-options.php#decipher">-decipher</a> option to unscramble your image so that it is recognizable once again. The option requires a filename that contains your passphrase. In this example we unscramble an image and save it in the JPEG format:</p>

<pre class="bg-light text-dark mx-4"><samp>magick rose.png -decipher passphrase.txt rose.jpg </samp></pre>
<pre class="bg-light text-dark mx-4 cli"><samp>magick rose.png -decipher passphrase.txt rose.jpg </samp></pre>

<h2><a class="anchor" id="caveats"></a>Encipher and Decipher Caveats</h2>

Expand Down
Loading

0 comments on commit 80f7b21

Please sign in to comment.