Didvide image into quarters - and save each?

Moderator: Kathy_9

Post Reply
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Didvide image into quarters - and save each?

Post by terrypin »

I've been searching for a script that will divide any image exactly into quarters and save each of those new files. So far without success, even on Suz Shook's excellent site.

Can anyone help me locate one please, or get me started on making one myself?

Alternatively, is there a really simple method to do this, in PSP 8, which I might then be able to copy with an external macro? My approach so far has been too reliant on careful positioning of the horizontal and vertical guideline to be amenable to a macro.

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
LeviFiction
Advisor
Posts: 6831
Joined: Thu Oct 02, 2008 1:07 pm
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Alienware M17xR4
processor: Intel Core i7-3630QM CPU - 2_40GH
ram: 6 GB
Video Card: NVIDIA GeForce GTX 660M
sound_card: Sound Blaster Recon3Di
Hard_Drive_Capacity: 500GB
Corel programs: PSP: 8-2023
Location: USA

Re: Didvide image into quarters - and save each?

Post by LeviFiction »

Do you have the Image Slicer command? I'm not sure when this was introduced.

Image Slicer can be found somewhere around File -> Export in later versions.

This dialog is meant to save out files for the web. It includes a "Grid" tool. When you click on the image using the grid tool it asks how many rows an columns. Enter 2 for both rows and columns to get 4 equal pieces. Then continue to use the dialog to save out the result. By default it tries to save as a GIF so you'll want to save out as a PNG orJPEG instead.

If you want a script, that should be fairly easy. Just need to create a script that creates a selection around each 1/4th of the image and copies it to a new image. Can't promise good results with this. Can't even promise it'll work in PSP8.

Code: Select all

from JascApp import *

def ScriptProperties():
    return {
        'Author': u'',
        'Copyright': u'',
        'Description': u'',
        'Host': u'PaintShop Pro',
        'Host Version': u''
        }

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {})
    
    rows = 2
    columns = 2
    
    CurrentDoc = App.TargetDocument
    
    w = CurrentDoc.Width
    h = CurrentDoc.Height
    
    cw = w/columns
    ch = h/rows

    for y in range(0,rows):
        for x in range(0,columns):
            top = y*ch
            left = x*cw
            # SelectNone
            App.Do( Environment, 'SelectNone', {}, CurrentDoc)

            # ModifySelection
            App.Do( Environment, 'ModifySelection', {
                    'Selection': ((left,top), left+cw, top+ch), 
                    'Type': App.Constants.SelectionModifyType.Custom, 'GeneralSettings':{'ExecutionMode': App.Constants.ExecutionMode.Silent}}, CurrentDoc)

            # Copy
            App.Do( Environment, 'Copy', {}, CurrentDoc)

            # PasteGraphicAsNewImage
            App.Do( Environment, 'PasteGraphicAsNewImage')
https://levifiction.wordpress.com/
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Didvide image into quarters - and save each?

Post by terrypin »

Yes! Thanks a bunch, that tool does exist and when I can get the hang of it I reckon it will be exactly what I need.

My immediate problem is that despite selecting PNG instead of the default GIF, only the top left slice gets saved as PNG, the other three as GIF. It's probably down to me, as I'm a bit unclear about the rather complex dialog. Presumably I can't simplify it by removing all references to HTML and web pages? I want to save merely the image slices, yet it seems I get this only as a by-product of saving an HTM.

When I better understand the tool itself, I'll study and try your script. Very kind of you to take the trouble.

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
terrypin
Posts: 492
Joined: Tue Jun 29, 2010 9:51 am
operating_system: Windows 10
System_Drive: C
32bit or 64bit: 64 Bit
motherboard: Asus Z170 Pro 4
processor: Intel Core i7 6700K 4.0GHz
ram: 32 GB
Video Card: None - uses built-in graphics
sound_card: HD onboard sound card
Hard_Drive_Capacity: 4.256 TB
Monitor/Display Make & Model: iLyama Prolite E2403WS 24" 1920x1200
Corel programs: Paint Shop Pro 8; Paint Shop Pro 2018
Location: East Grinstead UK

Re: Didvide image into quarters - and save each?

Post by terrypin »

Image Slicer
--------------
Happily, I eventually got that saving 4 PNGs.

Your script
------------
Works a treat thanks!

I did have a rather puzzling difficulty. After using Select All on your script in the forum post, all looked well. But when I pasted it into my text editor, it added four spaces to the left of all lines. So running it gave a syntax error. Pasting to Notepad added the same unwanted spaces. But after deleting those it worked OK. I'm assuming you intended that a selection needs to be made (ALL in my case) before running it?

Thanks again for all your help - much appreciated.

--
Terry, East Grinstead, UK
--
Terry, East Grinstead, UK
Using PSP 8 & PSP 2018 under Win 10
Post Reply