I have this script that saves out a .tif to the path PSD is open from.
The problem is that I cant for the life of me get it to save the file with a specific name. It always saves it as the PSD document name.
Please help, it's driving me insane.
(trying to save the file as "FOP")
PIA = app.activeDocument.layerSets.getByName("PIA");
FOP= PIA.layerSets.getByName("FOP");
FOP.visible = true;
var idsave = charIDToTypeID( "save" );
var desc255 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc256 = new ActionDescriptor();
var idBytO = charIDToTypeID( "BytO" );
var idPltf = charIDToTypeID( "Pltf" );
var idIBMP = charIDToTypeID( "IBMP" );
desc256.putEnumerated( idBytO, idPltf, idIBMP );
var idLZWC = charIDToTypeID( "LZWC" );
desc256.putBoolean( idLZWC, true );
var idsaveTransparency = stringIDToTypeID( "saveTransparency" );
desc256.putBoolean( idsaveTransparency, true );
var idTIFF = charIDToTypeID( "TIFF" );
desc255.putObject( idAs, idTIFF, desc256 );
var idIn = charIDToTypeID( "In " );
desc255.putPath( idIn, activeDocument.path, new File("FOP"));
var idDocI = charIDToTypeID( "DocI" );
desc255.putInteger( idDocI, 456 );
var idLyrs = charIDToTypeID( "Lyrs" );
desc255.putBoolean( idLyrs, false );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveBegin = stringIDToTypeID( "saveBegin" );
desc255.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc255, DialogModes.NO );
And this is similar to your other question: putPath only needs two arguments so it ignores new File("FOP") you're feeding to it. That line should look like this:
desc255.putPath( idIn, new File(activeDocument.path + "/FOP.tif"));
Also notice the / before the file name: activeDocument.path gives you a path without the final slash.
Related
I have multiple images like these
and a main photo one with which all others need to agree.
I want in all photos the little squares of the top row to be exactly on the same place(cause I use a Photoshop script to sample the color of each square's center using static coordinates). In many photos the camera moved a little so I need to adjust them (mostly vertically) to fix that. Do you know of any way that this can be done easily on many (cause I have like 1000 of them) photos?
I tried open like 30-40 in Photoshop at a time but need a way to place and keep some reference points. You know any way that this can be done? Maybe guides common for all opened files or something similar?
You can align vertical centres and then distribute the horizontal centres with code:
function align_tiny_photos()
{ // align and distribute
var idAlgn = charIDToTypeID( "Algn" );
var desc48 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref16 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref16.putEnumerated( idLyr, idOrdn, idTrgt );
desc48.putReference( idnull, ref16 );
var idUsng = charIDToTypeID( "Usng" );
var idADSt = charIDToTypeID( "ADSt" );
var idAdCV = charIDToTypeID( "AdCV" );
desc48.putEnumerated( idUsng, idADSt, idAdCV );
executeAction( idAlgn, desc48, DialogModes.NO );
var idDstr = charIDToTypeID( "Dstr" );
var desc62 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref23 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref23.putEnumerated( idLyr, idOrdn, idTrgt );
desc62.putReference( idnull, ref23 );
var idUsng = charIDToTypeID( "Usng" );
var idADSt = charIDToTypeID( "ADSt" );
var idAdCH = charIDToTypeID( "AdCH" );
desc62.putEnumerated( idUsng, idADSt, idAdCH );
executeAction( idDstr, desc62, DialogModes.NO );
}
To use:
align_tiny_photos();
before I totally give up on this idea I wanted to check with the three.js community to make sure that I'm not doing something wrong?
Essentially I have taken Mr doobs canvas geometry cube example http://mrdoob.github.io/three.js/examples/canvas_geometry_cube.html and applied an image to the cube faces. When testing on the iPad I have frame a frame speed of 1fps (as opposed to 60fps with the original example). The image also looks really broken up on rotation.
Are there any tricks on getting this to work well on the iPad? I'm aware that WebGL isn't supported but I thought the canvas renderer would perform better than it is?
Code below
Many thanks
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
var info = document.createElement( 'div' );
info.style.position = 'absolute';
info.style.top = '10px';
info.style.width = '100%';
info.style.textAlign = 'center';
info.innerHTML = 'Drag to spin the cube';
container.appendChild( info );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.y = 150;
camera.position.z = 500;
scene = new THREE.Scene();
// Cube
var loader = new THREE.TextureLoader();
loader.load( 'test-texture.png', function ( texture ) {
var materials = [];
var material = new THREE.MeshBasicMaterial( { map: texture, overdraw: 0.5 } );
material.transparent = true;
for ( var i = 0; i < 6; i ++ ) {
materials.push( material );
}
// then the cube definitions
cube = new THREE.Mesh( new THREE.CubeGeometry( 200, 200, 200,4,4,4), new THREE.MeshFaceMaterial(materials));
cube.position.y = 150;
scene.add( cube );
animate();
});
// Plane
var geometry = new THREE.PlaneGeometry( 200, 200 );
geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
var material = new THREE.MeshBasicMaterial( { color: 0xe0e0e0, overdraw: 0.5 } );
plane = new THREE.Mesh( geometry, material );
scene.add( plane );
renderer = new THREE.CanvasRenderer();
renderer.setClearColor( 0xf0f0f0 );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
container.appendChild( stats.domElement );
document.addEventListener( 'mousedown', onDocumentMouseDown, false );
document.addEventListener( 'touchstart', onDocumentTouchStart, false );
document.addEventListener( 'touchmove', onDocumentTouchMove, false );
//
window.addEventListener( 'resize', onWindowResize, false );
}
I would suggest to wait for iOS8 which should bring WebGL support.
**I have an air app for iOS I have been developing. I am trying to capture a picture, save the file to the storage directory (not Camera Roll), and save the file name in an sqlite db.
I have tried so many different variations of this, but when it comes to writing the filestream to save the app hangs. Testing on iPad 3. Does ANYONE have a suggestion? This has been driving me nuts for days. I have searched the web but I am stumped.**
public var temp:File; // File Object to save name in database
protected function selectPicture():void
{
myCam = new CameraUI();
myCam.addEventListener(MediaEvent.COMPLETE, onComplete);
myCam.launch(MediaType.IMAGE);
}
protected function onComplete(event:MediaEvent):void {
//imageProblem.source = event.data.file.url;
var cameraUI:CameraUI = event.target as CameraUI;
var mediaPromise:MediaPromise = event.data;
var mpLoader:Loader = new Loader();
mpLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMediaPromiseLoaded);
mpLoader.loadFilePromise(mediaPromise);
}
private function onMediaPromiseLoaded(e:Event):void
{
var mpLoaderInfo:LoaderInfo = e.target as LoaderInfo;
mpLoaderInfo.removeEventListener(Event.COMPLETE, onMediaPromiseLoaded);
this.imageProblem.source = mpLoaderInfo.loader;
var stream:FileStream = new FileStream();
stream.addEventListener(Event.COMPLETE, showComplete);
stream.addEventListener(IOErrorEvent.IO_ERROR, showError);
try{
this.messages.text = "Starting";
stream.open( temp, FileMode.WRITE );
stream.writeBytes(mpLoaderInfo.bytes);
stream.close();
}catch(e:Error){
this.messages.text = e.message;
}
}
protected function showError(e:IOErrorEvent):void{
this.messages.text = e.toString();
}
protected function showComplete(e:Event):void{
this.messages.text = "Completed Writing";
this.imgName.text = temp.url;
imagefile = temp;
deleteFlag = 1;
}
Application hangs due to you are trying to use file operation in Sync mode.
You need to use Async Mode operation instead of sync mode file operation.
stream.openAsync( temp, FileMode.WRITE );
Try with this
var stream:FileStream = new FileStream();
stream.addEventListener(Event.COMPLETE, showComplete);
stream.addEventListener(IOErrorEvent.IO_ERROR, showError);
stream.openAsync( temp, FileMode.WRITE );
stream.writeBytes(mpLoaderInfo.bytes);
stream.close();
Note when using async operation you need not use try catch.For handling error listen IOErrorEvent will catch if any error occurs.
I finally got this to work, I added comments below in the code to explain why it wasn't working.
public var temp:File;
protected function selectPicture():void
{
myCam = new CameraUI();
myCam.addEventListener(MediaEvent.COMPLETE, onComplete);
myCam.launch(MediaType.IMAGE);
}
protected function onComplete(event:MediaEvent):void {
//imageProblem.source = event.data.file.url;
var cameraUI:CameraUI = event.target as CameraUI;
var mediaPromise:MediaPromise = event.data;
var mpLoader:Loader = new Loader();
mpLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onMediaPromiseLoaded);
mpLoader.loadFilePromise(mediaPromise);
}
private function onMediaPromiseLoaded(e:Event):void
{
var mpLoaderInfo:LoaderInfo = e.target as LoaderInfo;
mpLoaderInfo.removeEventListener(Event.COMPLETE, onMediaPromiseLoaded);
this.imageProblem.source = mpLoaderInfo.loader;
/// Here was the solution
var bitmapDataA:BitmapData = new BitmapData(mpLoaderInfo.width, mpLoaderInfo.height);
bitmapDataA.draw(mpLoaderInfo.content,null,null,null,null,true);
/// I had to cast the loaderInfo as BitmapData
var bitmapDataB:BitmapData = resizeimage(bitmapDataA, int(mpLoaderInfo.width / 4), int(mpLoaderInfo.height/ 4)); // function to shrink the image
var c:CameraRoll = new CameraRoll();
c.addBitmapData(bitmapDataB);
var now:Date = new Date();
var f:File = File.applicationStorageDirectory.resolvePath("IMG" + now.seconds + now.minutes + ".jpg");
var stream:FileStream = new FileStream()
stream.open(f, FileMode.WRITE);
// Then had to redraw and encode as a jpeg before writing the file
var bytes:ByteArray = new ByteArray();
bytes = bitmapDataB.encode(new Rectangle(0,0, int(mpLoaderInfo.width / 4) , int(mpLoaderInfo.height / 4)), new JPEGEncoderOptions(80), bytes);
stream.writeBytes(bytes,0,bytes.bytesAvailable);
stream.close();
this.imgName.text = f.url;
imagefile = f;
deleteFlag = 1;
}
I'm using the AS3 code below to take a photo throught the cameraUI. Everything works fine on the Android but when I test on the iPad I get an error when trying to load the saved image. The ioErrorHandler1 returns:
ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2124: Loaded file is an unknown type. URL: app-storage:/myImage.jpg" errorID=2124]
Anyone know why? (as mentioned it works on Android). Here's the code:
function imageCaptured( event:MediaEvent ):void
{
trace( "Media captured..." );
var imagePromise:MediaPromise = event.data;
dataSource = imagePromise.open();
if( imagePromise.isAsync )
{
trace( "Asynchronous media promise." );
eventSource = dataSource as IEventDispatcher;
imageLoader = new Loader();
imageLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, asyncImageLoaded );
imageLoader.addEventListener( IOErrorEvent.IO_ERROR, cameraError );
imageLoader.loadFilePromise( imagePromise );
}
else
{
trace( "Synchronous media promise." );
imageLoader.loadFilePromise( imagePromise );
showMedia( imageLoader );
}
}
function asyncImageLoaded( event:Event ):void
{
readMediaData();
}
function readMediaData():void
{
var image:Bitmap = Bitmap(imageLoader.content);
var bitmap:BitmapData = image.bitmapData;
image.width = 100;
image.height = 100;
this.addChild(image);
var imageBytes:ByteArray = new ByteArray();
dataSource.readBytes( imageBytes );
var file:File = File.applicationStorageDirectory.resolvePath("myImage.jpg");
// create a file stream
var fs:FileStream=new FileStream();
// open the stream for writting
fs.openAsync(file, FileMode.WRITE);
// write the string data down to the file
fs.writeBytes(imageBytes);
// ok close the file stream
fs.close();
fs.addEventListener(Event.CLOSE,function(event:Event):void {
var mLoader=new Loader();
var mRequest:URLRequest = new URLRequest(file.url);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (event:Event):void{
showMediaLoad(mLoader);
});
mLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler1);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
mLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
mLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
mLoader.load(mRequest);
})
trace("saved");
}
You might need to encode your ByteArray before saving it as a jpeg.
Here's a snippet of code I used a while back...
import com.adobe.images.JPGEncoder;
private var f:File;
private var stream:FileStream;
private var j:JPGEncoder;
private var image:Bitmap = Bitmap(imageLoader.content);
private var urlRequest:URLRequest;
private var loader:Loader;
function saveImage():void {
f = File.documentsDirectory.resolvePath("logo.jpg");
stream = new FileStream();
stream.open(f, FileMode.WRITE);
j = new JPGEncoder(80);
var bytes:ByteArray = j.encode(image.bitmapData);
stream.writeBytes(bytes, 0, bytes.bytesAvailable);
stream.close();
stream.openAsync(f, FileMode.READ);
stream.addEventListener(Event.COMPLETE, loadImage, false, 0, true);
}
private function loadImage(e:Event):void {
stream.removeEventListener(Event.COMPLETE, loadImage);
stream = null;
//now load the image
if (f.exists == true) {
urlRequest = new URLRequest(f.url);
loader = new Loader;
loader.load(urlRequest);
loader.addEventListener(IOErrorEvent.IO_ERROR, function(e:IOErrorEvent):void{ trace(e) });
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, ImageLoaded, false, 0, true);
}
}
private function ImageLoaded(e:Event):void {
addChild(loader);
loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, ImageLoaded);
}
I found a solution. It works without jpgencoder if I put an eventlistener on the eventSource. I'm posting it here if anyone else could use the solution:
The imageCaptured function is updated like this:
if( imagePromise.isAsync )
{
trace( "Asynchronous media promise." );
var eventSource:IEventDispatcher = dataSource as IEventDispatcher;
eventSource.addEventListener( Event.COMPLETE, onMediaLoaded );
}
And then the image is save in this function:
function onMediaLoaded( event:Event ):void
{
trace("Media load complete");
var imageBytes:ByteArray = new ByteArray();
dataSource.readBytes( imageBytes );
var file:File = File.applicationStorageDirectory.resolvePath("myImage.jpg");
// create a file stream
var fs:FileStream=new FileStream();
// open the stream for writting
fs.openAsync(file, FileMode.WRITE);
// write the string data down to the file
//fs.writeBytes(imageBytes);
fs.writeBytes(imageBytes);
// ok close the file stream
fs.close();
fs.addEventListener(Event.CLOSE, function(e:Event):void {
var mLoader=new Loader();
var mRequest:URLRequest = new URLRequest(file.url);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function (event:Event):void{
showMediaLoad(mLoader);
});
mLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler1);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
mLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
mLoader.contentLoaderInfo.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
mLoader.load(mRequest);
}
Good day,
I have recently started playing with RingoJS along with Stick middleware and I am now stuck with sessions. I can't make it work.
main.js
var {Application} = require( "./_lib_/stick" ),
app = exports.app = Application();
app.configure( "mount" );
app.mount( "/", require( "./actions" ) );
if ( require.main === module ) {
require( "ringo/httpserver" ).main( module.directory );
}
actions.js
var {Application, helpers} = require( "./_lib_/stick" ),
Response = require( "ringo/jsgi/response" );
export( "app" );
var app = Application();
app.configure( "route", "render", "session" );
app.render.base = module.resolve( "templates" );
app.render.master = "page.html";
app.get("/session.htm", function( request ) {
//request.session.data.foo = "bar";
request.session.data.put("foo", "bar");
return Response.redirect( "session2.htm" );
});
app.get("/session2.htm", function( request ) {
var value = request.session;
return Response.html( "Session: " + value );
});
I've tested many combinaison but none of them worked as espected.
Most errors I get is about reading the data from the session. For example:
TypeError: Cannot read property "data" from undefined
Any tips?
"session" needs to come before "mount" in app.configure.
On the fourth line of main.js:
app.configure( "session", "mount" );
Then, remove "session" from the later call to app.configure since there's no point in running the middleware twice.