Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
#!/bin/bash
input=$1
tilesize=$2
if [ -z $tilesize ]; then tilesize=512; fi
skipfirsttile=$3
#dim=$(mediainfo --Output="Image;%Height%" $input)
dim=$(identify -format "%w" $input)
type=$(identify -format "%m" $input)
if [ $type = "MPC" ]
then
echo "good, input is already an MPC, we don't need to convert it"
mpc=$input
else
echo "will convert input image to MPC format before tiling"
mpc="${input%.*}"".mpc"
convert -verbose -monitor -limit memory 2G -limit map 4G $input $mpc
fi
lvl=$(./salado-level-calc.sh $dim)
if [ $skipfirsttile -eq 1 ]
then
echo "skipfirsttile parameter set, will continue with first resize operation now"
else
echo "tiling original image (lvl $lvl) now"
mkdir $lvl
./tile-mpc.sh $mpc $dim $tilesize "$lvl/"
fi
lvl=$[$lvl-1]
scale=2
mpcpre=$mpc
mpcl="${input%.*}""_lvl$lvl.mpc"
diml=$[$dim/$scale]
while [ $diml -gt $tilesize ]
do
echo "will resize for lvl $lvl with scale $scale -> edge length $diml into $mpcl now"
#for best quality, use $mpc as source, for faster processing, use $mpcpre
convert -verbose -monitor -limit memory 2G -limit map 4G "$mpcpre" -resize $diml"x"$diml "$mpcl"
echo "finished resize for lvl $lvl - will start tiling it now"
mkdir $lvl
./tile-mpc.sh $mpcl $diml $tilesize "$lvl/"
lvl=$[$lvl-1]
scale=$[$scale*2]
mpcpre=$mpcl
mpcl="${input%.*}""_lvl$lvl.mpc"
diml=$[$dim/$scale]
done
mkdir $lvl
convert -verbose -monitor -limit memory 2G -limit map 4G "$mpcpre" -resize $diml"x"$diml "$lvl/0_0.jpg"
update:
I've outsorced the functionality to find the right numbers for the pyramid-levels to an extra script, since I need floating point calculations for it:
#!/bin/bash
# Default scale used by float functions.
float_scale=2
#####################################################################
# Evaluate a floating point number expression.
function float_eval()
{
local stat=0
local result=0.0
if [[ $# -gt 0 ]]; then
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null)
stat=$?
if [[ $stat -eq 0 && -z "$result" ]]; then stat=1; fi
fi
echo $result
return $stat
}
#####################################################################
# Evaluate a floating point number conditional expression.
function float_cond()
{
local cond=0
if [[ $# -gt 0 ]]; then
cond=$(echo "$*" | bc -q 2>/dev/null)
if [[ -z "$cond" ]]; then cond=0; fi
if [[ "$cond" != 0 && "$cond" != 1 ]]; then cond=0; fi
fi
local stat=$((cond == 0))
return $stat
}
#####################################################################
# main script
dim=$1
scale=1
lvl=0
diml=$dim
while float_cond "$diml > 1"
do
#echo "$diml - $lvl"
scale=$[$scale*2]
diml=$(float_eval "$dim / $scale")
lvl=$[$lvl+1]
done
echo $lvl
so sadly this doesn't work anymore with new imagemagick versions. I've just converted a 2gb lzw compressed tiff file into an 93gb mpc (cache) file but upon trying to use this mpc file in another imagemagick call it copies it to the tmp directory instead of just reading it directly.
the mpc file has been created with IM7 and I'm using it with IM7. The problem is not that there is some incompatibility throwing an error, but that it's completely read and copied to a new temporary pixelcache file of the exact same size instead of it beeing just used directly like with whatever version I used in 2013. That ruins the performance of course since the associated cache file is 93gb in size and I was looking for the performance I got in 2013...
I just replaced all the "convert" calls with "magick" which gladly seems to have the same exact syntax, but the behavior is the same.
Can you distill the problem down to a one or two command lines? We tried these commands and the MPC file was memory-mapped and did not create the pixel cache on disk:
I've tried your example and unlike with my own mpc file it doesn't copy the cache when the second call runs, but it still reads the whole cache instead of just the part that it needs for the cropped area (and therefore takes minutes instead of seconds)
update: I've ran the second line a second time and timed it by putting `date +%H:%M:%S:%N` before and after the call in a bash script and it took nearly 5 minutes for the single crop run:
21:48:37:947840937
21:53:23:464553612
for the cache debug output see: https://pastebin.com/raw/VXaFejNQ
instead trying to create a tile of my own mpc fails because the default /tmp/ location only has 8gb space instead of the 93gb it's trying to copy there: