Tengo un archivo PSB grande (33600x19200px) y necesito escribir un script para exportar secciones de esta imagen como una serie de imágenes. ¿Cuál sería el mejor enfoque?
Inicialmente, pensé en secuencias de comandos y exportar, pero Guardar para Web está desactivado para esta resolución.
Otra opción que pensé fue esta:
Es este el mejor enfoque ? ¿Cuáles son sus sugerencias?
Actualizar:
Aquí está mi script con los pasos anteriores:
#target photoshop
var doc = app.activeDocument;
var sel = doc.selection;//main document selection
var rows = 70;
var cols = 40;
var cell = 240;//size of a cell/display image/region of interest
var space=240; //space in between cells
var dname = doc.name.substr(0,doc.name.length-4);
var dir = doc.path.toString()+"/";
var dpi72 = 182.88036576073152146304292608585;
var options = new ExportOptionsSaveForWeb();
options.format = SaveDocumentType.JPEG;
options.quality = 75;
//*
for(var y = 0; y < cols; y++){
for(var x = 0 ; x < rows; x++){
var xpos = (x * (cell+space))+((1-y%2) * space);//+ di-grid offset
var ypos = (y * (cell+space));
try{
sel.select([[xpos,ypos],[xpos+cell,ypos],[xpos+cell,ypos+cell],[xpos,ypos+cell]],SelectionType.REPLACE,0,false);
sel.copy(true);
var nname = dname + "_"+((x+1)) + "_" + ((y+1));
//$.writeln("["+x+"]["+y+"]" +nname +"\n"+sel.bounds);
//*
var small = app.documents.add(cell,cell,dpi72,dname,NewDocumentMode.RGB,DocumentFill.WHITE);
app.activeDocument = small;
small.paste();
small.exportDocument (new File(dir + "/" + nname + ".jpg"), ExportType.SAVEFORWEB, options);
small.close(SaveOptions.DONOTSAVECHANGES);
app.activeDocument = doc;
//*/
}catch(err){
x = rows;
y = cols;
alert(err);
}
}
}
El script funciona, pero es un poco lento. ¿Está bien mi enfoque o hay una forma más rápida de hacerlo?
Esto debería ser mucho más rápido . En lugar de copiar y pegar en un nuevo archivo cientos de veces, hace esto:
Calcula el número de celdas por fila, así como el número de filas. ¡No se necesita configuración previa!
Hay algunas variables que puede establecer al principio del archivo si alguna vez lo necesita.
NOTA: El script asume que comienza con un archivo plano y ASEGÚRESE DE TENER UNA COPIA DE SEGURIDAD de su obra de arte en caso de que algo salga mal.
En mi máquina en el trabajo (absolutamente nada elegante o poderoso, solo una PC batidora) creó los 350 mosaicos de su archivo de muestra en aproximadamente 6 minutos . Puede ayudar a la velocidad ocultando las herramientas y paletas (presionando Tab) antes de ejecutar el script. Además, minimizar Photoshop mientras se ejecuta el script también parece ayudar un poco.
// Alter these as needed
var cellWidth = 240; // The width, in px, of your image cell
var cellHeight = 240; // The height, in px, of your image cell
var xOffset = 240; // The space, in px, between each cell in a row
var yOffset = 240; // The space, in px, between each row. Set to 0 for traditional checker board effect
var options = new ExportOptionsSaveForWeb();
options.format = SaveDocumentType.JPEG;
options.quality = 75;
// Don't change these unless you know why you should! :)
var doc = app.activeDocument;
var dname = doc.name.substr(0,doc.name.length-4);
var dir = doc.path.toString()+"/";
var rowShift = true;
var imageWidth = activeDocument.width.as('px');
var imageHeight = activeDocument.height.as('px');
// Store the current rulerUnits for later. We're going to change
// it to pixels for now, and we want to change it back later.
var myRulerUnits = app.preferences.rulerUnits;
// Set rulerUnits to pixels
app.preferences.rulerUnits = Units.PIXELS;
// Find the "Background"
var layerRef = doc.artLayers.getByName("Background");
// Set our "Background" to be a Layer
layerRef.isBackgroundLayer = false;
// Reduce the Canvas size to our cell size
doc.resizeCanvas(cellWidth, cellHeight, AnchorPosition.TOPLEFT);
var totalOffset = 0;
var xMovement = 0;
// Do the magic
for (var y = 0; y < numberOfRows(); y++)
{
totalOffset = 0;
for (var x = 0; x < numberOfCells(); x++)
{
if (x == 0)
{
xMovement = (rowShift) ? xOffset : 0;
}
else
{
xMovement = cellWidth + xOffset;
}
totalOffset += xMovement;
// Offset the layer into our Canvas "window"
layerRef.applyOffset(-(xMovement), 0, OffsetUndefinedAreas.WRAPAROUND);
saveCell(x,y);
};
// Offset the layer back to the left and down one row
layerRef.applyOffset(totalOffset, -(cellHeight + yOffset), OffsetUndefinedAreas.WRAPAROUND);
// Flip the rowShift. If it was true, make it false and vice versa.
rowShift = !rowShift;
};
// Calculate number of cells per row. May change depending in rowShift, etc
function numberOfCells()
{
var theWidth = imageWidth;
if (rowShift == true)
{
var theWidth = theWidth - xOffset;
}
return Math.floor((theWidth + xOffset) / (cellWidth + xOffset));
}
// Calculate number of rows
function numberOfRows()
{
return Math.floor((imageHeight + yOffset) / (cellHeight + yOffset));
}
// Pad the cell x and y numbers for proper sorting
function pad(num, size)
{
var s = "000000000" + num;
return s.substr(s.length-size);
}
// Actually save, or really "Save For Web" the cell
function saveCell(x, y)
{
var nname = dname + "_" + pad((x + 1), 3) + "_" + pad((y + 1), 3);
doc.exportDocument (new File(dir + "/" + nname + ".jpg"), ExportType.SAVEFORWEB, options);
}
// Reset the ruler units
app.preferences.rulerUnits = myRulerUnits;
Copy > New Doc > Paste > Etc
era. Buenas ideas en tus modificaciones. Sin ver los originales, no tenía forma de saber qué otras cosas modificar. Hice otra versión que nombra los archivos un poco diferente con un número creciente en el nombre del archivo (como ctq_036_001_002.jpg), pero soy un poco TOC de esa manera. Buena suerte y si quieres modificarlo, estaré encantado de ayudarte si lo necesitas.
TunaMaxx
Jorge Profenza
TunaMaxx
Jorge Profenza
TunaMaxx
Jorge Profenza