Script carré

Scripts et tutoriels concernant les scripts
Règles du forum
Techniques pour gagner du temps ou automatiser des tâches
Répondre
Avatar du membre
fs999
entraideur expérimenté
entraideur expérimenté
Messages : 346
Enregistré le : sept. 2015
Sexe : Homme
Localisation : Luxembourg
OS : Windows 10
OS 64 bits : Oui
Version PSP : 2023 64 bits
Contact :

Script carré

Message par fs999 »

Voici une solution au problème ou bug de PaintShop Pro depuis pas mal de temps : Recadrer carré.
En changeant la taille, le recadrage n'est pas toujours carré, mais il y a souvent 1 à 3 pixels de plus d'un côté.

Voici un script pour retailler l'image en carré, à lancer après recadrage :

Code : Tout sélectionner

from PSPApp import *
import PSPUtils

def ScriptProperties():
    return {
        'Author': u'F.Schneider',
        'Copyright': u'\u00A9 2020 by F.Schneider',
        'Description': u'',
        'Host': u'PaintShop Pro',
        'Host Version': u'22.00'
        }

def Do(Environment):
    # EnableOptimizedScriptUndo
    App.Do( Environment, 'EnableOptimizedScriptUndo', {
            'GeneralSettings': {
                'ExecutionMode': App.Constants.ExecutionMode.Default, 
                'AutoActionMode': App.Constants.AutoActionMode.Match, 
                'Version': ((22,0,0),1)
                }
            })

    if PSPUtils.RequireADoc( Environment ) == False:
      return

    Width = App.ActiveDocument.Width
    Height = App.ActiveDocument.Height
    
    if Width != Height:
      if Width < Height:
        Height = Width
      else:
        Width = Height
        
      # ResizeCanvas
      App.Do( Environment, 'ResizeCanvas', {
              'AspectRatio': 1, 
              'FillColor': (0,0,0), 
              'HoriPlace': App.Constants.HorizontalType.Left, 
              'MaintainAspect': False, 
              'NewDimUnits': App.Constants.UnitsOfMeasure.Pixels, 
              'NewHeight': Height, 
              'NewWidth': Width, 
              'PlaceBottom': 0, 
              'PlaceLeft': 0, 
              'PlaceRight': 0, 
              'PlaceTop': 0, 
              'VertPlace': App.Constants.VerticalType.Top, 
              'GeneralSettings': {
                  'ExecutionMode': App.Constants.ExecutionMode.Silent, 
                  'AutoActionMode': App.Constants.AutoActionMode.Match, 
                  'Version': ((22,0,0),1)
                  }
              }) 
Avatar du membre
spitfrog
entraideur amiral
entraideur amiral
Messages : 3705
Enregistré le : juil. 2015
Sexe : Homme
Localisation : Normandie
OS : Windows 10
OS 64 bits : Oui
Version PSP : X4

Re: Script carré

Message par spitfrog »

Merci :salutchapeau: pour le partage
Répondre