Add flat amount to canvas size - photoshop

I want to have some automated process (either action or script) that will copy selection(assumes something has already been selected), place in new canvas, increase canvas size by exactly 10 pixels in height & width, then save it to the desktop.
I'm currently using an action and it works correctly with the exception of the 10 pixels part. I can do something like 10% by using the percentage adjustment in the canvas size menu, but I can't figure out how to do exactly 10 pixels. During the recording, if I just increase the canvas size by 10 pixels it'll record that exact amount (say it was 100x100, it records that I resized canvas to 110x100). So when I play that action on a selection that's of size 50x50 it resizes it to 110x110.... So the problem is that the action records the literal value of the canvas resize and not the add 10 pixels part...
Any ideas here?

This can be scripted as well, but if you've already got an action set up, try modifying your action to do the following:
paste the selection into new document larger than you expect to ever require
expand the selection by 10 px
crop the document to the selection
save
Or, to script it you can tweak the following sample. It assumes you have already copied your image to the clipboard:
#target photoshop
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var doc = app.documents.add('1000px');
var lyr = doc.artLayers.add();
doc.activeLayer = lyr;
doc.paste ();
var bnds = lyr.bounds;
var unitsToAdd = new UnitValue(10, 'px');
bnds[0] = bnds[0] - unitsToAdd;
bnds[1] = bnds[1] - unitsToAdd;
bnds[2] = bnds[2] + unitsToAdd;
bnds[3] = bnds[3] + unitsToAdd;
doc.crop(bnds) ;
doc.saveAs(new File('/c/temp/temp.psd'));

Related

How to convert PDF to image with same resolution as original PDF

I am using Aspose.Pdf to convert PDF to Image and latter convert Image back to Pdf. I would like to keep resolution, width and height of the new Pdf same as original Pdf.
using (var newDocument = new Document())
{
using (var originalDocument = new Document("c:\\source.pdf"))
{
foreach (Aspose.Pdf.Page page in originalDocument.Pages)
{
if (page.Rotate != Aspose.Pdf.Rotation.None)
{
using (var ms = new MemoryStream())
{
// Create Jpegdevice with specified attributes
// Width, Height, Resolution, Quality
// Quality [0-100], 100 is Maximum
// Create Resolution object
Resolution resolution = new Resolution(Convert.ToInt32(page.ArtBox.Width), Convert.ToInt32(page.ArtBox.Height));
JpegDevice device = new JpegDevice(resolution, 100);
// Convert a particular page and save the image to stream
device.Process(page, ms);
var newPage = newDocument.Pages.Add();
// Set margins so image will fit, etc.
newPage.PageInfo.Margin.Bottom = 0;
newPage.PageInfo.Margin.Top = 0;
newPage.PageInfo.Margin.Left = 0;
newPage.PageInfo.Margin.Right = 0;
// Create an image object
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
// Set the image file stream
image1.ImageStream = ms;
// Add the image into paragraphs collection of the section
newPage.Paragraphs.Add(image1);
// YES, save after every page otherwise we get out of memory exception
newDocument.Save(txtFolder.Text + "\\out.pdf");
}
}
else
{
newDocument.Pages.Add(page);
newDocument.Save(txtFolder.Text + "\\out.pdf");
}
}
}
}
Qustions
1> The original PDF size is 18MB but the above code creates large file of size 163MB. I would like keep the size as it is or least somewhat near to original file size by keeping the same resolution.
2>Resolution class also takes int valueX and int valueY parameters. And JpegDevice class takes int width and int height parameters. However it does not specify unit, weathers its in points, pixels, inches etc?
As per Aspose.Pdf documentation
The conversion from point to pixel depends on an image's DPI (dots per
inch) property. For example, if an image's DPI is 96 (96 pixels for
each inch), and it is 100 points high, its height in pixels is (100 /
72) * 96 = 133.3. The general formula is: pixels = ( points / 72 ) *
DPI.
However that does not answer the question what unit the API is asking?
Original Issue
We get PDF from our clients. Some of the PDF we receive has rotation of 90 or 270 degree. However when you open them in Adobe or any other PDF viewer, the page's orientation is correct (it is not landscape or horizontal). All this mess i have to do becuase Aspose.Pdf cannot keep the same orientation when change the rotation to None. So suggested approach is convert PDF to Image and latter convert Image back to Pdf
https://forum.aspose.com/t/cannot-set-cropbox-on-rotated-page/201659/3
https://forum.aspose.com/t/remove-rotation-from-a-document-and-set-it-upright/29170

How do you resize images by batch on photoshop where it scales based on the smaller dimension

I dont really know how to explain this, but..
How do you resize images by batch on photoshop where it scales based on the smaller dimension.
So basically, i want images to resize to 200x200 and I want the image to take the smaller dimension, center the image, then crop the excess of the bigger dimension.
Is there a way to do this?
I hope I make sense.
This script will resize the image so that the smallest dimension will become 200 and then crop it to 200 x 200
app.preferences.rulerUnits = Units.PIXELS;
// call the source document
var srcDoc = app.activeDocument;
var imageWidth = srcDoc.width.value;
var imageHeight = srcDoc.height.value;
var ts = 200;
if (imageHeight < imageWidth)
{
// landscape
var h = 200;
var w = Math.floor((imageWidth/imageHeight)*h);
}
else
{
// portrait
var w = 200;
var h = Math.floor((imageHeight/imageWidth)*w);
}
srcDoc.resizeImage(w, h, 72, ResampleMethod.BICUBIC);
//crop it in the centre
app.activeDocument.resizeCanvas(ts, ts, AnchorPosition.MIDDLECENTER);
You may need to use Actions and Automate in order to accomplish this. Here is a link to a tutorial:
http://www.digitalartsonline.co.uk/tutorials/photoshop/how-resize-multiple-images-in-photoshop/
Go to Image > Image Size.
This will bring up the Image Size dialog box, as shown below:
see documentation

libGDX autoresizing image button

i want a list with image buttons to be displayed in my libGDX app.
The idea is that the image has a size of lets say 400x100 pixels.
I need the list to be able to display the images stretched to width of the screen - the height of the image should be resized to keep the aspect ratio.
But everytime i try to do this the image won't get resized properly.
The image is not stretched when smaller then screen width or the padding get's bad or the aspect ration gets wrong.
Could you suggest a way to do this, i'm struggling to find any solution..
The actor must be Button a button.. (need "checked"/selected functionality)
I tried to do something like this:
Table table = new Table();
table.setFillParent(true);
Texture t1 = ... snip ...
Texture t2 = ... snip ...
ImageButton i1 = new ImageButton( new TextureRegionDrawable(new TextureRegion(t1));
ImageButton i2 = new ImageButton( new TextureRegionDrawable(new TextureRegion(t2));
i1.getImageCell().expandX().fillX();
i2.getImageCell().expandX().fillX();
table.add(i1).expandX().fillX();
table.row();
table.add(i2).expandX().fillX();
getStage().add(table);
This worked for me:
imageButton.setBounds(x, y, 128, 128);
imageButton.getImageCell().expand().fill();
float screenWidth = this.stage.getWidth();
i2.setWidth(screenWidth);
If i understand correctly, this should do what you want.

iTextSharp Overlay Image

Hi guys I have an instance where I have a logo image as part of some artwork..
If a user uploads a new logo I have a form field which is larger than the default logo.
I then use that form field to position the new image.
The problem is I need to set the background colour of that form field to white so that it covers the old logo in the event that the new image is smaller than the old logo..
what I have done is:
foreach (var imageField in imageReplacements)
{
fields.SetFieldProperty(imageField.Key, "bgcolor", iTextSharp.text.Color.WHITE, null);
fields.RegenerateField(imageField.Key);
PdfContentByte overContent = stamper.GetOverContent(imageField.Value.PageNumber);
float[] logoArea = fields.GetFieldPositions(imageField.Key);
if (logoArea != null)
{
iTextSharp.text.Rectangle logoRect = new iTextSharp.text.Rectangle(logoArea[1], logoArea[2], logoArea[3], logoArea[4]);
var logo = iTextSharp.text.Image.GetInstance(imageField.Value.Location);
if (logo.Width >= logoRect.Width || logo.Height >= logoRect.Height)
{
logo.ScaleToFit(logoRect.Width, logoRect.Height);
}
logo.Alignment = iTextSharp.text.Image.ALIGN_LEFT;
logo.SetAbsolutePosition(logoRect.Left, logoArea[2] + (logoRect.Height - logo.ScaledHeight) / 2);
// left: logoArea[3] - logo.ScaledWidth + (logoRect.Width - logo.ScaledWidth) / 2
overContent.AddImage(logo);
}
}
The problem with this is that the background colour of the field is set to white and the image then doesn't appear.. i remove the SetFieldProperty and RegenerateField commands and the image replacement works fine..
is there a way to set a stacking order on layers?
Annotations (such as form fields) are always on top of page contents. Annotation Z order is just the order of the annotations array on a given page.
Page content Z order is just the order everything appears in the content stream. New drawing operators go on top of proceeding operators.
If you want to cover your old image, draw a white box over it and then draw the new logo over top that. No need to worry about annotations.
Actually, all you really need to do is not set the background color of the imageField. You're already scaling the new logo to match the size of the old one.
However, if you really must draw that white box, it's fairly simple:
overContent.setColorFill(iTextSharp.text.Color.WHITE);
overContent.rectangle( logoRect );
overcontent.fill();

Ready An Existing PDF Page Size (ex. 8.5 x 11, 11 x 17) VB.Net

Like the title says i'd like to read an existing pdf page size with VB.Net. I've been working with Itext.Sharp, and the Acrobat.dll. Is this possible??
There are a number of different "Boxes" a given page can have:
Media Box (required): The initial page size when printing viewing.
Crop Box (optional): Supersedes the media box. Defaults to match the media box. Must be a subset or match the media box.
There's also art/trim/bleed boxes, but they don't matter as much and are much less common.
So, the page size:
PdfReader reader = new PdfReader(myPath);
// gets the MEDIA BOX
Rectangle pageRect = reader.getPageSize(1); // 1 -> first page
// gets the crop box if present, or the media box if not.
Rectangle cropRect = reader.getCropBox(1);
// and finally
Rectangle artBox = reader.getBoxSize( 1, "art");
// could be "art", "bleed", "crop", "media", or "trim"
I'd go with getCropBox().
I also recommend checking out the JavaDoc for things like this. At the very least you would have come up with getPageSize() on your own. No, it's not C#. Yes, it's very useful.
http://api.itextpdf.com/
Also note that these Rectangles need not be based on 0,0 (which would be the lower left corner on an unrotated page).
Further, you should check the page's rotation, getPageRotation(int), and swap height and width if the rotation is 90 or 270. There is getPageSizeWithRotation(int), but it only works with the media box, so I'd do it yourself if I were you. It's only a few extra lines of code:
// rotation has to be 0, 90, 180, or 270. "360" isn't kosher IIRC.
if (reader.getPageRotation(pageNum) % 180 != 0) {
float tmp = width;
width = height;
height = tmp;
}