Photoshop javascript - layer thumbnail as array/jpg/etc - photoshop

Does any1 know how to capture/get/pixel data of the little thumbnail image that we see in layers next to the eye/name of layer?
I have this example, but this code is for network fetching
var idNS = stringIDToTypeID( "sendDocumentThumbnailToNetworkClient" );
var desc1 = new ActionDescriptor();
desc1.putInteger( stringIDToTypeID( "width" ), 600 );
desc1.putInteger( stringIDToTypeID( "height" ), 400 );
desc1.putInteger( stringIDToTypeID( "format" ), 1 );
executeAction( idNS, desc1, DialogModes.NO );
I'm wondering if any1 has something similar to just grab the picture as is and return an array of chars/ints/etc/jpg etc?
I want to capture 4000 pictures in a document so will try to port it to c++ afterwards.
Regards
Dariusz

Related

How to create batch two-sided pdf page in Photoshop or similar software?

I have 100 PSD files with different content and another 1 separate psd file that want to combine in two-side PDF document (Front and Back).
It's for print. I want to Automate process because the files are many. So, for example let's say that for the first (front page) I have 100 PSDs with different image inside for example: (in PSD-01 - > img-01), (in PSD-02 -> img-02), ... and the second page (the BACK) is the same for all Front Pages. For example PSD1 must combine with Back PSD, PSD2 must combine with BACK PSD and etc...
How can I automate this process in Photoshop, or InDesign, or other program, so when created files to have 100 Double-Sided PDFs with Different first (front) page and the same second (back) page? Thanks.
Basically it can be done in InDesign with this script:
var doc = app.activeDocument;
if (doc.pages.length < 2) doc.pages.add();
// put image on page 2
var file = 'd:/temp/back_page.psd';
place_image_on_page(file, doc.pages[1]);
// get PSD files for page 1
var files = Folder('d:/temp/front').getFiles('*.psd');
var output_folder = Folder('d:/temp/pdf');
// show progress bar
var bar = new Window("palette", "Progress...");
var stat = bar.add("statictext", undefined, "");
var progressbar = bar.add("progressbar", [15,15,400,35], 0, 100);
stat.characters = 50;
bar.center();
bar.show();
// loop through the files
for (var f in files) {
// delete old and put new image on page 1
try { doc.pages[0].rectangles[0].remove() } catch(e) {}
place_image_on_page(files[f], doc.pages[0]);
// export the doc in PDF
var preset = app.pdfExportPresets.item("[High Quality Print]");
var file_name = parseInt(f) + 1 + '.pdf';
var pdf_file = File(output_folder + '/' + file_name);
// update the progress bar
progressbar.value = ++f/files.length*100;
stat.text = 'Make ' + file_name;
bar.update();
doc.exportFile(ExportFormat.pdfType, pdf_file, false, preset);
}
bar.close()
alert('Done!');
// ----------------------------------------------------------------------------
function place_image_on_page(file, page) {
var img = page.place(File(file));
doc.align(img, AlignOptions.HORIZONTAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
doc.align(img, AlignOptions.VERTICAL_CENTERS, AlignDistributeBounds.PAGE_BOUNDS);
img[0].parent.fit(FitOptions.FRAME_TO_CONTENT);
}
Put your files in these folders:
d:/temp/back_page.psd -- PSD for page 2 (back page)
d:/temp/front/*.psd -- PSD files for page 1 (front page)
d:/temp/pdf/ -- folder for PDF files
Create empty InDesign document with correct size and run the script. It saves two-side PDFs in the folder d:/temp/pdf. Names of these pdf files will be 1.pdf, 2.pdf, 3.pdf etc.
You can automate it with Photoshop scripting:
Say you have your pageA and pageB as .png files.
// Switch off any dialog boxes
displayDialogs = DialogModes.NO; // OFF
// you need to change these!!!!
var frontPage = "D:\\temp\\process_images\\page_A.png";
var backPage = "D:\\temp\\process_images\\page_B.png";
var myPDF = "D:\\temp\\process_images\\myPDF.pdf";
// =======================================================
var idPDFExport = stringIDToTypeID( "PDFExport" );
var desc6139 = new ActionDescriptor();
var idflst = charIDToTypeID( "flst" );
var list844 = new ActionList();
list844.putPath( new File( frontPage) );
list844.putPath( new File( backPage ) );
desc6139.putList( idflst, list844 );
var idT = charIDToTypeID( "T " );
desc6139.putPath( idT, new File( myPDF ) );
var idBckC = charIDToTypeID( "BckC" );
var idBckC = charIDToTypeID( "BckC" );
var idWht = charIDToTypeID( "Wht " );
desc6139.putEnumerated( idBckC, idBckC, idWht );
var idAs = charIDToTypeID( "As " );
var desc6140 = new ActionDescriptor();
var idpdfPresetFilename = stringIDToTypeID( "pdfPresetFilename" );
desc6140.putString( idpdfPresetFilename, """High Quality Print""" );
var idpdfPreserveEditing = stringIDToTypeID( "pdfPreserveEditing" );
desc6140.putBoolean( idpdfPreserveEditing, false );
var idpdfCompressionType = stringIDToTypeID( "pdfCompressionType" );
desc6140.putInteger( idpdfCompressionType, 7 );
var idPhtP = charIDToTypeID( "PhtP" );
desc6139.putObject( idAs, idPhtP, desc6140 );
executeAction( idPDFExport, desc6139, DialogModes.NO );
You just need to adjust the script so it loops over your 100 front images and then adds the same back page.

stats.js shows FPS 0~2, render movement too slow

i'm beginner for three.js also using it for BIM project,
when i load a gltf file of ~25mb i can barely move the whole object and stats.js monitor shows fps of 0~2 at max
gltf file : https://github.com/xeolabs/xeogl/tree/master/examples/models/gltf/schependomlaan
im using THREE js with vuejs
//package.json
"stats.js": "^0.17.0",
"three": "^0.109.0",
import * as THREE from 'three';
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
this.scene = new THREE.Scene();
this.stats = new Stats();
this.stats.showPanel( 0, 1, 2 ); // 0: fps, 1: ms, 2: mb, 3+: custom
let div = document.createElement('div')
div.appendChild(this.stats.dom)
div.style.position = 'absolute';
div.style.top = 0;
div.style.left = 0;
document.getElementsByClassName('gltfViewer')[0].appendChild( div );
// Camera
this.camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1500 );
this.camera.position.set( this.pos, this.pos, this.pos );
// renderer
this.raycaster = new THREE.Raycaster();
this.renderer = new THREE.WebGLRenderer({ canvas: document.getElementById('gltfViewerCanvas'), alpha: false });
this.renderer.setClearColor( 0xefefef );
this.renderer.setPixelRatio( window.devicePixelRatio );
this.renderer.setSize(window.innerWidth, window.innerHeight);
// adding controls
this.controls = new OrbitControls( this.camera, this.renderer.domElement );
this.controls.dampingFactor = 0.1;
this.controls.rotateSpeed = 0.12;
this.controls.enableDamping = true;
this.controls.update();
window.addEventListener('resize', _ => this.render());
this.controls.addEventListener('change', _ => this.render());
// light
var ambientLight = new THREE.AmbientLight( 0xcccccc );
this.scene.add( ambientLight );
var directionalLight = new THREE.DirectionalLight( 0xffffff );
directionalLight.position.set( 0, 1, 1 ).normalize();
this.scene.add( directionalLight );
// loading gltf file
// Instantiate a loader
this.gltfLoader = new GLTFLoader();
// Optional: Provide a DRACOLoader instance to decode compressed mesh data
this.dracoLoader = new DRACOLoader();
this.dracoLoader.setDecoderPath( 'three/examples/js/libs/draco' );
this.gltfLoader.setDRACOLoader( this.dracoLoader );
// Load a glTF resource
this.gltfLoader.load( this.src, this.onGLTFLoaded, this.onGLTFLoading, this.onGLTFLoadingError );
//onGLTFLoaded()
this.scene.add( optimizedGltf.scene );
// gltf.scene.getObjectById(404).visible = false;
this.listGltfObjects(gltf);
this.render();
// render ()
this.renderer.render( this.scene, this.camera );
this.stats.update();
// on mounted component :
animate()
// animate()
this.stats.begin()
this.render();
this.stats.end();
even after applying Draco compression using https://github.com/AnalyticalGraphicsInc/gltf-pipeline nothing changes.
Thanks
On filesize —
Draco compression reduces network size, but not the final amount of uncompressed data that must be sent to your GPU and rendered. If your original mesh was 100mb and you compress it to 25mb, you will still get the framerate of the original 100mb mesh. Aside: Using the -b option of glTF-Pipeline will reduce the size by another 50%, to 13MB, but again doesn't affect FPS.
On framerate —
This model contains 4280 meshes1, each requiring a GPU draw call. That is the source of your low QPS, and unfortunately it's a common problem in BIM models. You'll need to merge these meshes (in a program like Blender, or after loading in three.js) to as few as possible. A model like this should require < 100 draw calls, or even as few as 1.
1 To see this, try opening the model on https://gltf-viewer.donmccurdy.com/ and opening the JavaScript console. You should see a printout of the scene graph, which will contain many different meshes.

Import image with threejs in VueJS project

I followed threejs documentation in vuejs project to import image using :
texture.load( "./clouds" )
This code is not working, I have to import image using require :
texture.load( require( "./clouds.png" ) )
Now I want to use functions for sucess or error, so thank's to the internet i found that
texture.load( require( "./clouds.png" ), this.onSuccess, this.onProgress, this.onError )
The problem is in success function, I want to create a cube with texture and nothing happened. I also tried on success function to add color in material but it didn't work.
onSuccess( image ) {
this.material = new THREE.MeshLambertMaterial( {
color: 0xf3ffe2,
map: image
}
this.generateCube()
}
generateCube() {
let geometry = new THREE.BoxGeometry( 100, 100, 100 );
this.forme = new THREE.Mesh( geometry, this.material );
this.forme.position.z = -200
this.forme.position.x = -100
this.scene.add( this.forme );
},
Your problem is not related to VueJS /ThreeJs (again ^^), you should learn how to use this inside a callback, here is a E6 fix :
texture.load( require( "./clouds.png" ), t => this.onSuccess(t), e => this.onProgress(e), e => this.onError(e) )
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
You can put your images in the "public" folder.
And then you can load your texture by
texture.load( "/clouds.png" )

how to convert base64 code to image in magento 2

i am creating magento api that receives the base64 encoded image code .
from api side i receive the that string.now i have to convert that image code and save into required destination.
how to achieve this in magento 2.can i get that image name from that encoded image.please help with this.
I have a code to convert base 64 to image in php. But i want know whether same code works in magento evnvironment
function base64_to_jpeg( $base64_string, $output_file ) {
$ifp = fopen( $output_file, "wb" );
fwrite( $ifp, base64_decode( $base64_string) );
fclose( $ifp );
return( $output_file );
}
$image = base64_to_jpeg( $my_base64_string, 'tmp.jpg' );
inject these in your constructor:
\Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $MediaGalleryEntry,
\Magento\Framework\Api\Data\ImageContentInterface $imageContentInterface,
During product creation I do something like this:
$mediaGalleryEntry = $this->_mediaGalleryEntry;
$mediaGalleryEntry->setLabel($name);
$mediaGalleryEntry->setTypes(array("image","small_image","thumbnail"));
$mediaGalleryEntry->setStoreIds($storeIds);
$mediaGalleryEntry->setMediaType('image');
$mediaGalleryEntry->setPosition(0);
$imageContent = $this->_imageContentInterface;
$imageContent->setName($name);
$imageContent->setType($imageType);
$imageContent->setBase64EncodedData($imageData);
$mediaGalleryEntry->SetContent($imageContent);
$product->setMediaGalleryEntries(array($mediaGalleryEntry));

wxDataViewListCtrl display incorrect when not default size

Copying the code from the wxDataViewListCtrl documentation
wxDataViewListCtrl *listctrl = new wxDataViewListCtrl( myPanel, wxID_ANY );
listctrl->AppendToggleColumn( "Toggle" );
listctrl->AppendTextColumn( "Text" );
wxVector<wxVariant> data;
data.push_back( wxVariant(true) );
data.push_back( wxVariant("row 1") );
listctrl->AppendItem( data );
data.clear();data.push_back( wxVariant(false) );
data.push_back( wxVariant("row 3") );
listctrl->AppendItem( data );
Produces a reasonable result
Now I want to make the control bigger and move it slightly down and to the right. So I change the call to the constructor to
wxDataViewListCtrl *listctrl = new wxDataViewListCtrl( myPanel, wxID_ANY
,wxPoint(10,10),wxSize(200,100) );
The result is the control frame resizes and moves correctly, but the contents vanish
The is wxWidgets v3.0.0 built with codeblocks and mingw g++
Found a workaround: call setSize after appending items
wxDataViewListCtrl *listctrl = new wxDataViewListCtrl( myPanel, wxID_ANY );
... append items ...
listctrl->SetSize(200,100);