joonaspaakko / Batch-Mockup-Smart-Object-Replacement-photoshop-script

Batch Mockup Smart Object Replacement - Photoshop script - A script that can batch process multiple mockup files and is able to replace multiple smart objects per mockup.
95 stars 22 forks source link

Cannot set e exact size #35

Open Fatihcnky opened 3 months ago

Fatihcnky commented 3 months ago

I cannot resize the photo to a certain size. For example, I want it to be 1170x836 px, but it does not work, so my photo is cut from the bottom and top. Is there any option or code for it ? Thank you.

joonaspaakko commented 3 months ago

It's not really designed to work that way. Generally speaking when you're resizing images you either: resize/crop to fill, or resize to fit, or the worst case scenario: stretch the image. The last option is omitted from the script with the notion that it's always better to retain the aspect ratio than to stretch your images.

So with that said, to output at a specific size, you're firstly at the mercy of the target smart object. If you want the output to have a square that is let's say exactly 100x100px, you make the smart object (inside the mockup PSD) exactly 100x100px. Then to fit the square perfectly without cropping you could use resize: 'fit'. This is sort of where the problems start with your situation, because if you have different size input images, which I'm going to presume you do, landscape images will just end up with white space at the top and bottom, so the height won't be 100px but rather however tall it has to be to retain aspect ratio and portrait images end up with white space at the sides, again not 100px wide but rather however wide it has to be to retain aspect ratio and still fit inside the target area. Of course, if your input files have the same aspect ratio as the smart object (square), they will output fitting inside the smart object perfectly without cropping away anything or having to stretch the image.

Caveat: All resize options except resize: false have an offset of a few pixels to combat anti-aliasing at the edges of the images, so the background doesn't shine through the edges, so a tiny bit is probably going to be cropped off even with fit, though perhaps it's not enough for you to care about.

If your input files don't have the same aspect ratio and you don't mind stretching them, batch resize (stretch) your input files before feeding them to the script. Another option is to use the option inputPlaced_runScript and run a script that checks the current document (smart object) dimensions and stretches the currently active layer (input image) to that exact size. This would also disregard the anti-alias offset I was talking about. Pre-processing the input files is likely far easier if you're not familiar with javascript but it will add an extra step to the entire process.

Pre-processing or not, when your input files are exactly the size of your target smart object you can use options trimTransparency: false, resize: false so as long the smart object is the same size, that's what it will output. This example is talked about in here a little bit.

This is likely irrelevant, but there are also two resize options called: xFill or yFill (potentially confusing names), both of which are designed for input files like screenshots so that you can fit the smart object let's say horizontally no matter what the aspect ratio is so that the screenshot will always fill the width of the document and the height will either fall short or overflow.

I may have to refresh my memory a bit at some point to make sure I didn't forget something.

joonaspaakko commented 3 months ago

By the way, could you confirm if the script works? Yesteday I was told it doesn't, or at least that the standalone example didn't, even without changing anything: https://github.com/joonaspaakko/Batch-Mockup-Smart-Object-Replacement-photoshop-script/issues/34#issuecomment-2173067049

Fatihcnky commented 3 months ago

The stretch option may solve my problem, but I don't know how to implement it. Visually, I have added the current resize and what I want below. Can you simply explain what I should do by writing what on which line? and the example works without any problems. I use the example with some modifications and it has no problems except for resizing. Thank you for your help and this excellent code. Adsız Ekran görüntüsü 2024-06-19 153226 `

include "script/Batch Mockup Smart Object Replacement.jsx"

var output = { path: './_output files', // Outputs next to the mockup psd format: 'jpg', // 'jpg', 'png', 'tif', 'psd', 'pdf' filename: '@mockup - @input', };

mockups([

// Mockup #1 { output: output, mockupPath: '$/assets/f2.psd', smartObjects: [

  // Smart object #1
  {
    target: 'smart2',
    input: [
      './_input files'
    ], 
    inputNested: true,
    align: 'center center',
    resize: 'stretch', 
  },

  // You could have more smart objects per mockup file...
  // {},

]

}, // Mockup #2 { output: output, mockupPath: '$/assets/fatih_kapak.psd', smartObjects: [

  // Smart object #2
  {
    target: 'smart1',
    input: [
      './_input files'
    ], 
    inputNested: true,
    align: 'center center',
    resize: 'stretch', 
  },

  // You could have more smart objects per mockup file...
  // {},

]

}, // Mockup #3 { output: output, mockupPath: '$/assets/f3.psd', smartObjects: [

  // Smart object #3
  {
    target: 'smart3',
    input: [
      './_input files'
    ], 
    inputNested: true,
    align: 'center center',
    resize: 'stretch', 
  },

  // You could have more smart objects per mockup file...
  // {},

]

}, // Mockup #4 { output: output, mockupPath: '$/assets/f4.psd', smartObjects: [

  // Smart object #4
  {
    target: 'smart4',
    input: [
      './_input files'
    ], 
    inputNested: true,
    align: 'center center',
    resize: 'extend', 
  },

  // You could have more smart objects per mockup file...
  // {},

]

}, // Mockup #5 { output: output, mockupPath: '$/assets/f5.psd', smartObjects: [

  // Smart object #5
  {
    target: 'smart5',
    input: [
      './_input files'
    ], 
    inputNested: true,
    align: 'center center',
    resize: 'extend', 
  },

  // You could have more smart objects per mockup file...
  // {},

]

}, // Mockup #6 { output: output, mockupPath: '$/assets/f6.psd', smartObjects: [

  // Smart object #6
  {
    target: 'smart6',
    input: [
      './_input files'
    ], 
    inputNested: true,
    align: 'center center',
    resize: 'extend', 
  },

  // You could have more smart objects per mockup file...
  // {},

]

}, // Mockup #7 { output: output, mockupPath: '$/assets/f7.psd', smartObjects: [

  // Smart object #7
  {
    target: 'smart7',
    input: [
      './_input files'
    ], 
    inputNested: true,
    align: 'center center',
    resize: 'extend', 
  },

  // You could have more smart objects per mockup file...
  // {},

]

}, // You could have more mockup files... // {},

]);

`

joonaspaakko commented 3 months ago

That's is never the right way to go about it. I would seriously urge you not to stretch (or actually in this case squish) the images... It's practically criminal to do that. If cropping is unacceptable, then so should be disregarding the aspect ratio.

I would fix this issue by making sure the smart object is the same aspect ratio as these input files or if that is not viable make sure the input files are the same aspect ratio as the smart object, so no cropping or squishing needs to happen. Or perhaps you could use resize: 'fit' instead. Perhaps I didn't explain it well enough in my last comment, but that would make sure everything stays inside the boundaries.

If you want to spit in the face of graphic design gods... And I sigh just thinking about it (depression growing deeper by the minute)... There are many ways / applications to bach resize images. Photoshop is not necessarily the simplest, because there are applications that pretty much do it with a single button press, but you can batch resize images in Photoshop quite easily. Resize all your input files to 1170x836px and then run the script with resize: false.

Fatihcnky commented 3 months ago

The resize: 'fit' option doesn't work for me because it creates white spaces around the edges. I am using more than one mockup and the smart objects are not the same size, so as you said, if I change the image size, it will not work for the other mockups. I think there's no way to stretch or squash the image. Still, really nice code, thanks. image

joonaspaakko commented 3 months ago

I didn't understand this "I think there's no way to stretch or squash the image"

Resize all your input files to 1170x836px and then run the script with resize: false.

I found you a Youtube tutorial and everything.

Fatihcnky commented 3 months ago

I mean 'I think there's no way to stretch or squash the image' with this code. I use multiple mockups and the smart objects' sizes are different so if I resize my input files to 1170x836 its work for only one mockup. I Watched the tutorial, but this way I have to make bath resize for each mockup and create a different code file or edit it every time I use different mockup.

joonaspaakko commented 3 months ago

Alright. I would make sure every input has the right aspect ratio, even if it means making multiple versions for multiple mockups. Or if that is too much work I would settle for resize: "fill". Stretching is never the solution... Never.

Fatihcnky commented 3 months ago

I understood thank you.