Page 1 of 1

Patterning an image?

Posted: 2018-12-16T16:35:48-07:00
by Pastah
Version: ImageMagick 7.0.8-16 Q16 x86_64 2018-12-10

Hey all I'm new to using image magick. So far I've been dabbling with bash scripts utilizing it. Currently I'm having issues trying to to use a sample/pattern of the top left 100x100 pixels to pattern across the rest of the image. The finishing result looks distorted, the colors look wrong, and it looks really bad. I assume resaving a jpg over and over causes a lot of artifacts. Help?

Here's my bash script:

Code: Select all

#!/bin/bash

width=$(identify -ping -format '%w' $1[0])
height=$(identify -ping -format '%h' $1[0])
back="back.jpg"
sample="sample.jpg"
divW=$(( "$width" / 100 ))
divH=$(( "$height" / 100 ))


cp "$1" "$back"
for (( i=0; i<=$divW; i++ )); {
  for (( j=0; j<=$divH; j++ )); {
    magick "$back" \( +clone -crop 100x100+0+0 \) -geometry +$(( i * 100 ))+$(( j * 100 )) -composite "$back"
  }
}

Re: Patterning an image?

Posted: 2018-12-16T16:50:07-07:00
by snibgo
Pastah wrote:I assume resaving a jpg over and over causes a lot of artifacts.
Yes. Jpg is a lossy format. Try a non-lossy format instead, such as png.

Re: Patterning an image?

Posted: 2018-12-16T16:59:27-07:00
by GeeMack
Pastah wrote: 2018-12-16T16:35:48-07:00Currently I'm having issues trying to to use a sample/pattern of the top left 100x100 pixels to pattern across the rest of the image.
Using ImageMagick 7 you should be able to do that in a single command that would look something like this...

Code: Select all

magick input.png -crop 100x100+0+0 \
   -set option:distort:viewport %[fx:page.width]x%[fx:page.height] \
   -virtual-pixel tile -distort SRT 0 +repage output.png
The finishing result looks distorted, the colors look wrong, and it looks really bad. I assume resaving a jpg over and over causes a lot of artifacts.
That's correct. JPG losses will compound with repeated processing and saving.