[solved] Need help with copy pixels - resize and paste into another region

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
Avanatus
Posts: 9
Joined: 2016-07-08T01:45:55-07:00
Authentication code: 1151

[solved] Need help with copy pixels - resize and paste into another region

Post by Avanatus »

Hello all,
I searched but did not find the solution - maybe someone can help me.

Original: Format *.dds - size 128x128 - position region: 25,36 - size region: 71x48

i want to convert to:

Converted: Format *.dds - size 64x64 - position region: 12,16 - size region: 34x24

I try the convert Option.

Resize to 64x64 works - code for my batchfile:
for %%f in (*.dds) do ( convert %%f -resize 64x64 -define dds:mipmaps=2 -define dds:compression=none "converted\%%f" )

In the moment i would like to do:
1. copy region from original to new image (tempimage1)
2. resize(tempimage1) to new size (tempimage2)
2. create transparent canvas from original (tempimage3)
3. resize transparent canvas(tempimage2) to new size (tempimage4)
4. copy (tempimage2) to new region (tempimage4) (outputimage1)

Is there a way with options to do it in one go? - so without the tempimage's?

would be nice if someone can help me on that topic :-)

Thanks for help

Avanatus
Last edited by Avanatus on 2016-07-08T12:22:00-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need help with copy pixels - resize and paste into another region

Post by snibgo »

I don't understand what you want. Perhaps you want to:

(1) From an input image that is 128x128, make an output that is 64x64. You have done that.

(2) From the same input image, crop out an area 71x48+25+36, resize that to 34x24, and paste that over the output at offset 12,16.

Is that what you want?

(2) could be:

Code: Select all

convert output.dds ( input.dds -crop 71x48+25+36 +repage ) -geometry 12,16 -compose Over -composite output.dds
Adjust syntax as needed for your shell.
snibgo's IM pages: im.snibgo.com
Avanatus
Posts: 9
Joined: 2016-07-08T01:45:55-07:00
Authentication code: 1151

Re: Need help with copy pixels - resize and paste into another region

Post by Avanatus »

Hello snibgo,
yes thats what i want to do :-)

All seems clear to me except where you resize the image to 34x24....?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need help with copy pixels - resize and paste into another region

Post by snibgo »

Sorry, yes, I forgot the resize.

Code: Select all

convert output.dds ( input.dds -crop 71x48+25+36 +repage -resize 34x24 ) -geometry 12,16 -compose Over -composite output.dds
If the two converts do what you want, you can then combine them into a single convert.
snibgo's IM pages: im.snibgo.com
Avanatus
Posts: 9
Joined: 2016-07-08T01:45:55-07:00
Authentication code: 1151

Re: Need help with copy pixels - resize and paste into another region

Post by Avanatus »

Hi snibgo,
i am working on a windows desktop with win7

At first i had problems with directorys with spaces in it, so i changed to directorys without spaces in the names.

Now all worked until your code^^.

Here is the batchfile i am using:

Code: Select all

del tempimage1\*.dds
del tempimage2\*.dds
del tempimage3\*.dds
del outputimage1\*.dds

:: Batchfile for ImageMagick - by ava 06072016
:: Converting DDS files from 128x128 into 64x64 DDS Files and replacing the position

::Turn of displaying the code on the screen
@echo on

:: Read all the dds images from the directory, resize them, and save as a dds in a different directory
setLocal ENABLEDELAYEDEXPANSION
SET IMCONV="%PROGRAMFILES%\ImageMagick"

CD %~p1
for %%f in (*.dds) do (
set filename=%%~nf
set filepath=%%~pf
convert "%%f" -crop 71x48+25+36 -define dds:compression=none "!filepath!tempimage1\!filename!.dds"
)

cd tempimage1
for %%f in (*.dds) do ( 
set filename=%%~nf
convert "%%f" -resize 34x24 -define dds:compression=none "!filepath!tempimage2\!filename!.dds"
)

cd..
for %%f in (*.dds) do (
set filename=%%~nf
convert "%%f" -alpha transparent -resize 64x64 -define dds:compression=none "!filepath!tempimage3\!filename!.dds"
)

cd tempimage3
for %%f in (*.dds) do (
set filename=%%~nf
convert "%%f" ( "!filepath!\!filename!.dds" -crop 71x48+25+36 +repage -resize 34x24 ) -geometry 12,16 -compose Over -composite "!filepath!outputimage1\!filename!.dds"
)

:: -define dds:compression={dxt1, dxt5, none}

endlocal
pause
The batchfile works until the convert inside the convert....
Maybe a syntax error?

Thanks for help

Avanatus
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need help with copy pixels - resize and paste into another region

Post by snibgo »

When your command contains parentheses ( and ) within a "for" if "if" parentheses, you need to escape them.

Code: Select all

convert "%%f" ^( "!filepath!\!filename!.dds" -crop 71x48+25+36 +repage -resize 34x24 ^) -geometry 12,16 -compose Over -composite "!filepath!outputimage1\!filename!.dds"
snibgo's IM pages: im.snibgo.com
Avanatus
Posts: 9
Joined: 2016-07-08T01:45:55-07:00
Authentication code: 1151

Re: Need help with copy pixels - resize and paste into another region

Post by Avanatus »

Thanks snibgo - it helps....

Now i get an error from the convert module "convert: invalid geometry `12,16' @ error/geometry.c/ParseRegionGeometry/1542."

Hmpf^^
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need help with copy pixels - resize and paste into another region

Post by snibgo »

See the manual at http://www.imagemagick.org/script/comma ... p#geometry and follow the link. It gives you the required syntax.
snibgo's IM pages: im.snibgo.com
Avanatus
Posts: 9
Joined: 2016-07-08T01:45:55-07:00
Authentication code: 1151

Re: Need help with copy pixels - resize and paste into another region

Post by Avanatus »

Ahh... thanks :-)

Forgot the + sighns^^

now:

Code: Select all

convert "%%f" ^( "!filepath!\!filename!.dds" -crop 71x48+25+36 +repage -resize 34x24 ^) -geometry +12+16 -compose Over -composite "!filepath!outputimage1\!filename!.dds"
)
...works like a charm^^

Thanks a million for help

Avanatus
Avanatus
Posts: 9
Joined: 2016-07-08T01:45:55-07:00
Authentication code: 1151

Re: Need help with copy pixels - resize and paste into another region

Post by Avanatus »

How can i set the thread to "solved"?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Need help with copy pixels - resize and paste into another region

Post by fmw42 »

Avanatus wrote:How can i set the thread to "solved"?
Edit the title of your very first (top) post in this thread.
Avanatus
Posts: 9
Joined: 2016-07-08T01:45:55-07:00
Authentication code: 1151

Re: [solved] Need help with copy pixels - resize and paste into another region

Post by Avanatus »

Done - and thanks for help :-)
Post Reply