Patterning an image?

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?".
Post Reply
Pastah
Posts: 1
Joined: 2018-12-16T16:28:32-07:00
Authentication code: 1152

Patterning an image?

Post 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"
  }
}
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Patterning an image?

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Patterning an image?

Post 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.
Post Reply