Drag a corner of an image in DM triggers the image content refreshed to the new window size. What is the DM script command to trigger that refreshing?
Specifically, I want to add a text below the image. So, I get the imageDocument as root component, add a text annotation below the image (the vertical position of the text is beyond the bottom border of the image). Without "imgDoc.ImageDocumentSwitchToPageMode()", the text is not visible. When I change the image size with mouse, the image content is updated and the text is shown. Looking for script doing that.
Thanks,
The command you're seeking is void ImageDocumentOptimizeWindow( ImageDocument imgDoc )
but there is a bit more to the story:
You can add annotations (which really are Components ) to any other Component. An ImageDisplay is also a specialization of a Component. Thus, you may either add text as an annotation on an ImageDisplay - or on an ImageDocument.
If the first, then the text will move & resize when you move/resize the ImageDisplay, but if you add it to the ImageDocument's root component, it is "side-ordered" to and independent of the ImageDisplay on the page.
Here is a code example for either:
image test := RealImage("Test",4,512,512)
test=icol
test.ShowImage()
imageDisplay disp = test.ImageGetImageDisplay(0)
imageDocument doc = test.ImageGetOrCreateImageDocument()
If ( TwoButtonDialog("Add as part of Image or Page?","Image","Page") )
{
component text1 = NewTextAnnotation( 10, 550, "Under image as part of ImageDisplay", 20)
disp.ComponentAddChildAtEnd(text1)
doc.ImageDocumentOptimizeWindow()
}
else
{
component text2 = NewTextAnnotation( 10, 550, "Under image as part of ImageDocument", 20)
doc.ImageDocumentEnsurePlacedOnPage()
doc.ImageDocumentSwitchToPageMode()
doc.ImageDocumentGetRootComponent().ComponentAddChildAtEnd(text2)
}
To better understand the structure of things, you may want to run a script like the following on an ImageDocument:
void RecursiveListChildren( component parent, string preFix )
{
number numChild = parent.ComponentCountChildren()
Result("\n"+preFix+" [Type "+parent.ComponentGetType()+"]")
for( Number i =0; i<numChild; i++ )
RecursiveListChildren( parent.ComponentGetChild(i), prefix + "..." )
}
component root = GetFrontImageDocument().ImageDocumentGetRootComponent()
ClearResults()
RecursiveListChildren(root,".")
For the two documents of the first script, this will give you:
. [Type 24]
.... [Type 20]
....... [Type 13]
and
. [Type 24]
.... [Type 20]
.... [Type 13]
For new GMS 2.x or higher, the answer is void ImageDocumentOptimizeWindow( ImageDocument imgDoc ). Not tested.
For older GMS, a generic solution is like this,
void resetImageDisplay(image img) {
imageDisplay imgDsp=img.ImageGetImageDisplay(0)
imageDocument imgDoc = img.ImageGetOrCreateImageDocument()
imgDoc.ImageDocumentSwitchToPageMode()
imgDoc.ImageDocumentSwitchToImageMode(imgDsp)
}
void main() {
image img:=exprSize(512,512, random())
img.showImage()
imageDisplay imgDsp=img.ImageGetImageDisplay(0)
component comp1=imgDsp.NewTextAnnotation(200, 540, "text 1", 14)
component comp2=imgDsp.NewTextAnnotation(200, 560, "text 2", 18)
comp1.ComponentSetForegroundColor(0,0,0)
comp2.ComponentSetForegroundColor(0,0,0)
imgDsp.ComponentAddChildAtEnd(comp1)
imgDsp.ComponentAddChildAtEnd(comp2)
img.resetImageDisplay()
//img.setWindowSize(1024,1024)
}
main()
Related
It's my first time using reportlab to generate pdfs, it's VERY hard for me to understand how it works (it took me a day to even put a sized SVG image :D)
I want to achieve a very basic pdf:
As you can see in the images: 1 cover page, then 2 pages with header and footer BUT header with text is only on the first page...
Text is not static at all, it can break up to 4-5 pages, in the future there could be another section with title with different text.
Also I think what is very hard is to set text's Frame.topPadding to be variable based on
header height... I can't even imagine how to do this xD
This is my code right now
I've achieved to do the first page, it was pretty easy, but when it came to Frames, PageTemplates and other, my head blew up...
def _header(self, canvas, doc, title=None):
# Save the state of our canvas so we can draw on it
canvas.saveState()
y_pad = 50
header_height = (y_pad * 2) + (self.styles['heading'].leading if text else 0)
header_frame = Frame(
x1=0,
y1=self.height - header_height,
width=self.width,
height=header_height,
topPadding=y_pad,
bottomPadding=y_pad
)
canvas.setFillColor(DARKGRAY)
canvas.rect(0, self.height - header_height, self.width, header_height, fill=1)
if text:
header_frame.addFromList([
Paragraph(text, self.styles['heading'])
], canvas)
# Release the canvas
canvas.restoreState()
def _dark_page(self, canvas, doc):
canvas.saveState()
canvas.setFillColor(DARKGRAY)
canvas.rect(0, 0, self.width, self.height, fill=1)
canvas.restoreState()
def _create(self):
doc = SimpleDocTemplate(
self.buffer,
topMargin=0,
rightMargin=0,
leftMargin=0,
bottomMargin=0,
pagesize=A4
)
story = []
# cover page template with dark background set by self._dark_page
main_page_template = PageTemplate(id='main', frames=[
Frame(0, 0, self.width, self.height, 0, 100, 0, 100)
], onPage=self._dark_page)
# basic page template for any further text about product
body_page_template = PageTemplate(id='body', frames=[
Frame(0, 0, self.width, self.height, 80, 120, 80, 120, showBoundary=1)
], onPage=lambda c,d: self._header(c, d, title='title title title title')
doc.addPageTemplates([main_page_template, body_page_template])
story.append(NextPageTemplate('main'))
logo = svg2rlg(LOGO_PATH)
logo.width = logo.minWidth() * 0.4
logo.height = logo.height * 0.4
logo.scale(0.4, 0.4)
# logo._showBoundary = 1
logo.hAlign = 'CENTER'
story.append(logo)
story.append(Spacer(width=0, height=80))
# maybe there's a way to position the image in the center between elements,
# like justify-content: between in css...
image = Image(self._get_product_image_path(), 320, 320)
story.append(image)
story.append(Spacer(width=0, height=80))
title = Paragraph(self.product.title, self.styles['heading'])
story.append(title)
if self.product.breed.name_latin:
story += [
Spacer(width=0, height=10),
Paragraph(self.product.breed.name_latin, self.styles['subheading'])
]
story.append(NextPageTemplate('body'))
story.append(PageBreak())
# actual text
story.append(Paragraph(text*4, self.styles['body']))
doc.build(story)
So the question is
How do I set header and footer on the page, and if page breaks, next page with same header and footer, but header without title until the last page of the PageTemplate?
I've tried to get page numbers in self._header doc argument, but it's returning the first page number of the PageTemplate, not every page, maybe there's a way to get a page number from 0(first page used by some template) to the last page used by this template?
THANKS in advance! It already took me 3 days to try to achieve this...
I have a lot of graphic buttons that I need to make. I have 2 layers
TEXT (This is going to be numbers 1-48 for instance)
White Button image
I'm not sure how to go about writing this action or if I need a script. I need to have the text layer start at 1 and follow this progression.
save file w1.png (this yields a png with a button labeled with a "1"
change text to 2
save file w2.png (this yields a png with a button labeled with a "2"
change text to 3
. . . .
ect. . .all the way to 48. So this would make 48 images automatically. Can this be done with "actions" or do I need to learn scripting?
Save
You'll need a script for this, but it's going to be a rather simple one
function main() {
//this just checks if you have a text layer selected
try {
var textLayer = activeDocument.activeLayer.textItem
} catch (e) {
alert("active layer isn't a text layer");
return
};
var loops = 48,
pngSaveOptions = new PNGSaveOptions(),
outputFolder = Folder.selectDialog('', Folder.desktop); //this will ask for an output folder
for (var i = 0; i < loops; i++) {
var myNum = i + 1;
textLayer.contents = myNum; //this will change layer contents to number only. if you need some text here, write it in quotes like textLayer.contents = "my text" + myNum;
activeDocument.saveAs(new File(outputFolder + "/w" + myNum + ".png"), pngSaveOptions, true, Extension.LOWERCASE);
}
}
app.activeDocument.suspendHistory("temp", "main()");
CleanImage( BasicImage )
allows to delete an image without getting the dialog: "Do you want to save ..."
Apart from adding zero to the whole image (8k by 8k), is there a counter part? Like:
DirtyImage( BasicImage )
Thanks!
No, such a command does not exist, but it also isn't really useful.Any action on an imageDocument will automaticaly mark it dirty (i.e. needs to be saved), so you can easily do this by f.e. adding/removing a tag; setting a pixelvalue temporarily; moving the window, etc.
The command CleanImage() is just a convenience feature really. The actual property "is different from stored file" is a property of the the ImageDocument, the stuff that gets saved to disc.
As a consequence, the command isn't really doing anything to images which do not have an ImageDocument, i.e. image variables which have never been shown, saved, or had ImageGetOrCreateImageDocument() called on them. You can see this here:
image img := RealImage( "test", 4, 100, 100 )
If ( TwoButtonDialog("Show?","Yes","No") )
img.ShowImage()
If ( TwoButtonDialog("Try closing before cleaning?","Yes","No") )
img.CloseImage()
else
{
img.CleanImage()
img.CloseImage()
}
The command really matches to:
void ImageDocumentClean( ImageDocument imgDoc )
and the command to check if an imageDocument needs saving is
Boolean ImageDocumentIsDirty( ImageDocument img_doc )
So, more typically one would use these commands instead, as I do in the scripts below.
The following script shows how you can easily "dirty" an imageDocument just by re-setting one of the pixels value. Note that this script works independently of having the image displayed, because we explicitly create the ImageDocument.
Result( "\n Create Image... ")
image img := RealImage( "test", 4, 100, 100 )
Result( "\n Get it's ImageDocument... ")
imageDocument doc = img.ImageGetOrCreateImageDocument()
Result( "\n Is it dirty? --> " + (doc.ImageDocumentIsDirty()?"Yes, dirty":"No, clean"))
Result( "\n Clean it!" )
doc.ImageDocumentClean()
Result( "\n Is it dirty? --> " + (doc.ImageDocumentIsDirty()?"Yes, dirty":"No, clean"))
Result( "\n Make it dirty by setting the first pixel value to the value it has..." )
img.SetPixel(0,0,img.GetPixel(0,0))
Result( "\n Is it dirty? --> " + (doc.ImageDocumentIsDirty()?"Yes, dirty":"No, clean"))
However, I am curious in when such a functionality would ever be needed?
I'm looking for good CMS for publishing software manuals.
Requirements:
publish manual pages as web pages with thumbnails and shows full resolution after click on image,
exporting manual pages to a pdf file with full resolution images instead to thumbnails.
I found IMHO best wiki system named Tiki Wiki (https://info.tiki.org/) but when I export to pdf then I gets low resolution thumbnail.
I solve this problem by very simple Tiki Wiki code modification:
Modify lib/wiki-plugins/wikiplugin_img.php to force using full image resolution instead to thumbnail in print page mode (inserted code 1) and rescale images in generated HTML by 0.5 factor (inserted code 2):
[...]
function wikiplugin_img( $data, $params )
{
[...]
$imgdata = array_merge($imgdata, $params);
// inserted code 1 (~410 line)
if ($GLOBALS['section_class']=="tiki_wiki_page print"){
$imgdata['thumb'] = '';
}
// end of inserted code 1
//function calls
if ( !empty($imgdata['default']) || !empty($imgdata['mandatory'])) {
[...]
$fwidth = '';
$fheight = '';
if (isset(TikiLib::lib('parser')->option['indexing']) && TikiLib::lib('parser')->option['indexing']) {
$fwidth = 1;
$fheight = 1;
} else {
// inserted code 2 (~410 line)
if ($GLOBALS['section_class']=="tiki_wiki_page print"){
$fwidth = $imageObj->get_width() / 2;
$fheight = $imageObj->get_height() / 2;
} else {
$fwidth = $imageObj->get_width();
$fheight = $imageObj->get_height();
}
// end of inserted code 2 (~638 line)
}
[...]
Now, after printing to pdf by wkhtmltopdf we gets pdf with small but full resolution images.
Additional modifies:
Adds following lines to cms/cssmenus.css (or other css included in print mode) for increase bottom margin of image caption:
div.thumbcaption {
margin-bottom: 5mm;
}
Removes lines from 171 to ~175 in templates/tiki-show_content.tpl for remove the "The original document is available at" foot.
I have never scripted in photoshop before, so I am wondering if this is possible. The following is currently done manually for over than 300 files. The next time round is for 600 files, therefore I am looking into automating it.
Steps:
Make Image Size to 54pixels Hight and 500px Width -- Found that this is doable.
Align Image Left.
Create a text layer and insert text -- Found that this is doable.
Align Text layer 1px to the right of the image.
Trim empty space.
Would appreciate any help and pointers. Thanks.
This script will get you started: Note that in your request you didn't mention what what the original image was going to be and shrinking it to 500 x 54 is going to stretch it one way or another. Step 2, Align the image left, was omitted as you didn't mention what you are aligning this image to. I suspect you are dealing with a large image and what to shrink it down (as long as it's not smaller than 500 x 54) and work from there. I've also omitted stage 4 as I've hard coded the position of the text to be 1 px from the right hand edge (and it vertically centered with Arial font size 18)
Anhyoo.. you should be able to alter the script to your needs.
// set the source document
srcDoc = app.activeDocument;
//set preference units
var originalRulerPref = app.preferences.rulerUnits;
var originalTypePref = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.POINTS;
app.preferences.typeUnits = TypeUnits.POINTS;
// resize image (ignoring the original aspect ratio)
var w = 500;
var h = 54;
var resizeRes = 72;
var resizeMethod = ResampleMethod.BICUBIC;
srcDoc.resizeImage(w, h, resizeRes, resizeMethod)
//create the text
var textStr = "Some text";
createText("Arial-BoldMT", 18.0, 0,0,0, textStr, w-1, 34)
srcDoc.activeLayer.textItem.justification = Justification.RIGHT
//set preference units back to normal
app.preferences.rulerUnits = originalRulerPref;
app.preferences.typeUnits = originalTypePref;
//trim image to transparent width
app.activeDocument.trim(TrimType.TRANSPARENT, true, true, true, true);
// function CREATE TEXT(typeface, size, R, G, B, text content, text X pos, text Y pos)
// --------------------------------------------------------
function createText(fface, size, colR, colG, colB, content, tX, tY)
{
// Add a new layer in the new document
var artLayerRef = srcDoc.artLayers.add()
// Specify that the layer is a text layer
artLayerRef.kind = LayerKind.TEXT
//This section defines the color of the hello world text
textColor = new SolidColor();
textColor.rgb.red = colR;
textColor.rgb.green = colG;
textColor.rgb.blue = colB;
//Get a reference to the text item so that we can add the text and format it a bit
textItemRef = artLayerRef.textItem
textItemRef.font = fface;
textItemRef.contents = content;
textItemRef.color = textColor;
textItemRef.size = size
textItemRef.position = new Array(tX, tY) //pixels from the left, pixels from the top
}
Everything you listed is doable in a script. I suggest you start by reading 'Adobe Intro To Scripting' in your ExtendScript Toolkit program files directory (e.g. C:\Program Files (x86)\Adobe\Adobe Utilities - CS6\ExtendScript Toolkit CS6\SDK\English)