Resize images and expand canvas

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Bob87

Resize images and expand canvas

Post by Bob87 »

Hi,

I am new to this, so I actually have no idea if the thing I try to achieve is possible. That's why I'm here.
I am having 1000 images of different sizes. The thing I want to do is to have images all of 250x250px.

I already thought about it, i think it should have to check if the width is the largest or the height. Then scale that largest width/height to 250 px and scale the corresponding height/width with the same aspect ratio. Then it should enlarge the canvas size to 250x250px with a white background color.

I just really don't have an idea if this is possible, and doing this manual will take me ages!

Thanks!

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

txuku

Resize images and expand canvas

Post by txuku »

Bonjour Bob87

You can take a look at this topic : Simple resizing script - Help
Bob87

Resize images and expand canvas

Post by Bob87 »

Thanks! I am going to take a look at it, at first sight this is just what I need

Hero!
Bob87

Resize images and expand canvas

Post by Bob87 »

Hi,

I tried to use it, but it is causing an error...

What i did: I took the script and put it in a .txt file, then I renamed it to a .jsx. Then in photoshop cs5, I went to File - scripts - browse and selected the .jsx file. It asks me to select the folder, it all goes well at first sight, but then suddenly it stops and gives following error:

Code: Select allError 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop. -The parameters for command "Save" are not currently valid. Line: 129 -> app.activeDocument.saveAs(File(filename),jpegOptions, false);

It stops at a .gif file of 250x250 px. Maybe it has something to do with the fact that I also asked to set it to 250x250? It doesn't stops with all the other images, which are different sizes than 250x250..
I tested now with other images of 250x250, they have the error as well...

line 129 is
Code: Select allapp.activeDocument.saveAs( File( filename), jpegOptions, false);

Is it possible to use "save for web" instead(to reduce the storage size?)?

Thanks!!
txuku

Resize images and expand canvas

Post by txuku »

Hum...

By using save for web :

Code: Select all//Resize250.jsx

startRulerUnits = app.preferences.rulerUnits;
startTypeUnits = app.preferences.typeUnits;
startDisplayDialogs = app.displayDialogs;


app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;



var exportFolder = new Folder('~/Desktop/'+"OUT");
if(!exportFolder.exists) exportFolder.create();



var docRef = app.activeDocument;
var tailleRedim = 250;
var tailleRedimH = undefined;
var tailleRedimV = undefined;
var docRef1Name = docRef.name.slice(0,-4);
var jpgFile = new File( exportFolder + "/" + "250_"  + docRef1Name + ".jpg" );

var docRefH = parseInt(docRef.width);
var docRefV = parseInt(docRef.height);
var propDimH = docRefH/docRefV;
var propDimV = docRefV/docRefH;



if ( docRefH>docRefV )
{
      if ( docRefH<=tailleRedim )
      {
        tailleRedim = docRefH;
        tailleRedimH = docRefH;
        reDimension();
      }
      else
      {       
          tailleRedimH = tailleRedim;
          reDimension();
      }
}
else

      if ( docRefV<=tailleRedim )
      {
        tailleRedim = docRefV;
        tailleRedimV = docRefV;
        reDimension();
      }
      else
      {       
          tailleRedimV = tailleRedim;
          reDimension();
      }
}



function reDimension()
{
  if ( ( docRef.width == docRef.height ) && ( docRefH<=tailleRedim ) )
  {
    docRef.duplicate( docRef1Name );
    docRef1 = app.activeDocument;
    docRef.close(SaveOptions.DONOTSAVECHANGES);
    saveWebJpg(jpgFile);
  } 
   
  else
  {
    docRef.resizeImage( tailleRedimH, tailleRedimV, undefined, ResampleMethod.BICUBIC );
    docRef.selection.selectAll()
    docRef.selection.copy();
    docRef.close(SaveOptions.DONOTSAVECHANGES);
    docRef1 = app.documents.add(tailleRedim, tailleRedim, 72, docRef1Name , NewDocumentMode.RGB,      DocumentFill.WHITE,1);
    docRef1.paste();
    docRef1.flatten();
    saveWebJpg(jpgFile);
  } 
}

 



function saveWebJpg(jpgFile)
{
      var options = new ExportOptionsSaveForWeb();
      options.quality = 100;   // Start with highest quality (biggest file).
      options.format = SaveDocumentType.JPEG;   // Or it'll default to GIF.
      activeDocument.exportDocument(jpgFile, ExportType.SAVEFORWEB, options);
  activeDocument.close(SaveOptions.DONOTSAVECHANGES)
}   



app.preferences.rulerunits = startRulerUnits;
app.preferences.typeunits = startTypeUnits;
app.displayDialogs = startDisplayDialogs;
Bob87

Resize images and expand canvas

Post by Bob87 »

I mixed it into the other code so it threats a whole folder now!

Also, I changed to PNG Thanks for the help man!
txuku

Resize images and expand canvas

Post by txuku »

Bob87

Resize images and expand canvas

Post by Bob87 »

Hi txuhu, I'll hope you still read this, otherwise I will start a new post, because it is kind of a new problem.
Is there also a way to change the image mode to RGB color in case of the original file is a .gif file? The scaling is of real bad quality when opening and resizing .gif images...

Thanks man, hope you can help me out
txuku

Resize images and expand canvas

Post by txuku »

Bonjour Bob87

You can use Code: Select allactiveDocument.changeMode(ChangeMode.RGB);// passe en RGB
but the quality will not change !
Bob87

Resize images and expand canvas

Post by Bob87 »

It actually does have another effect on the quality of the picture. Try it yourself in photoshop! Resizing an gif image to for example 150x150 will have a different look than the ones after changing to RGB color.

Anyway, thanks again massively!