Improving Precision when scaling to exact pixel size

Hi All,
I'm very new to javascript and illustrator scripting, so I'm pretty sure my problem might be easily fixed
I'm trying to write a script for creating PNGs with a specified pixel size.  I have created the following functions, which first works out the scaling % to use based on the artboard size (borrowed the idea from this post -thanks MuppetMark), and then export the image to PNG.
It works, but, I am finding that when scaling to larger sizes, the resultant output is often a few pixels different from the value I have specified.  I'm sure this is due to precision/rounding issues in javascript, but have no idea how to fix.
I'd be really grateful of any suggestions
Many thanks
Tim
function getScaleFactor(artboard, width, height)
var scaleFactor;
if (width > 0)
        var scaleFactor = ( width / ( artboard.artboardRect[2] - artboard.artboardRect[0] ) ) * 100;
else if (height > 0)
        scaleFactor = ( height / ( artboard.artboardRect[1] - artboard.artboardRect[3] ) ) * 100;
else
    scaleFactor = 100.0;
return scaleFactor;
function exportFileToPNG24 (dest, scaleFactor) {
    if ( app.documents.length > 0 ) {
        var exportOptions = new ExportOptionsPNG24();
        var type = ExportType.PNG24;
        var fileSpec = new File(dest);
        exportOptions.antiAliasing = true;
        exportOptions.transparency = true;
        exportOptions.saveAsHTML = false;
        exportOptions.artBoardClipping = true;
        exportOptions.horizontalScale = scaleFactor;
        exportOptions.verticalScale = scaleFactor;
        app.activeDocument.exportFile( fileSpec, type, exportOptions );

What you type in that box is just the ratio not the actual pixel number. And the box does not like to many digits in there. A ratio of 4 x 5 would work perfectly fine in your case, but more complicated ratios like 21 x 50 don't work.
To get 500 x 400 px you must then export your image with settings that restrict your image, eg, to fit into a 500 x 500 px box.
The idea behind this two-step approach is that you might think of 500 x 400 px output right now, but by doing the actual pixel generation at a later point, you can always easily export later at 1000 x 800 px if you need a higher resolution version with the same aspect ratio.

Similar Messages

  • Cropping images to exact pixel sizes

    I'm a Photoshop user but being a recent Mac convert I'm having a go with the Aperture 2 trial.
    I'm a bit confused about how to crop an image to an exact pixel size. I've watched the video tutorial several times over but I still can't achieve what I want. So ...
    * My original image is 2816 x 2112
    * I select a 4 x 3 aspect ratio using the Crop HUD
    * I pull the rectangular box out to take in the section of the image I want to crop out of the original
    * I want a finished image of 500 x 400 pixels
    * I go to the Crop field in the Adjustments tab and change Width to 500 and the Height to 400
    * The crop area on the image ends up as a small box in the bottom left hand corner and when I hit Return, all I end up with is that area of the image inside the box when what I want is the originally selected crop area but at 500 x 400 pixels
    * If I stretch the rectangular box out to cover the original area, the pixel dimensions go up again beyond 500 x 400
    Which part of the process am I missing?
    Thanks for anyone's advice,
    Mark

    What you type in that box is just the ratio not the actual pixel number. And the box does not like to many digits in there. A ratio of 4 x 5 would work perfectly fine in your case, but more complicated ratios like 21 x 50 don't work.
    To get 500 x 400 px you must then export your image with settings that restrict your image, eg, to fit into a 500 x 500 px box.
    The idea behind this two-step approach is that you might think of 500 x 400 px output right now, but by doing the actual pixel generation at a later point, you can always easily export later at 1000 x 800 px if you need a higher resolution version with the same aspect ratio.

  • Pixelated images when scaled down issue.

    I have scaled down some JPG's in flash and they look fine but
    when I publish to a SWF they look pixelated. I've read other
    threads and done what is suggested i.e. Smoothing on or off, JPG's
    instead of PNG's and quality at 100% with no success. I know that
    Flash isn't a resolution based application and bitmaps are but the
    images look fine in the Flash IDE.
    Can anybody help me further with this. Thanks in advance for
    any help.
    Simon.

    Hi andy 3r x1...I'm not sure I understand what you mean,
    sorry. I have JPG's inside flash and they look fine but when I
    publish and view them through the player they don't. The JPG's are
    scaled in the flash movie but are seen 1:1 later on in the movie.
    The scaled versions are pixelated.
    Anyhow, I've found what the problem is. I'm publishing for
    Flash player 7. If I publish for 8 and above the JPG's look fine.
    Haven't got a clue why this is other then the players are better?!?

  • How do I change the pixel size when converting Word doc to .pdf?

    When converting a Word Document to .pdf the file size is too large. How do I reduce the pixel size?

    Typically a Word file's content is text which has not image association.
    For whatever images might be in the Word file you'd want to adjust image resolution in an image editor prior to bringing the image into the Word file from which the PDF is made.
    Be well...

  • When I open icloud, desktop is opened with a pixel size of 640 x 480

    When I open icloud, desktop is opened with a pixel size of 640 x 480
    The normal pixel size is 1680 x 1050 on my desk.
    This means that I can not turn the button so all the settings are installed.
    How to solve this problem?
    I use Internet Explore as your browser.
    Operating system is windoes 7 ultimate.

    Move the cursor to the very top of the screen, maybe push up a bit. The main menubar should then appear. All the way to the right should be a bright blue icon - click it, and the Safari window should revert to 'normal' size.
    Pressing Command-Control-F should accomplish the same thing.
    Once it is back to normal size, click and hold on the top portion of the Safari window and drag to left or right to place it where you want it to be. Once you leave it there, the next time you open Safari it should open its window in normal size at that place.
    If you need to re-size the window a bit, you can click-and-hold on the bottom-right corner of the window and drag to resize it.

  • Scaling two objects to match exactly pixel to pixel.

    I have two art objects on two layers. I want to match to the pixel the two objects that otherwise could be exactly the same but one layered object was imported slightly smaller. The scale tool has good scale handling, I just want to measure the tool spots to the pixel to gain an exact scale size factor and match sizes.

    If they could be the same  size what caused the scale difference. Were the images taken with or different cameras, or different focal length or angle are you sure only the scale is off.  That the perspectives and sizes of the objects are the same. Photoshop has a measure tool just remember perspective, angle, axis all effect the measurements size.

  • How come a font set at a certain pixel size is not actually that size when you measure it's height? For example, a font set at size 24 pixels is actually only 16 pixels tall (cap height).

    How come a font set at a certain pixel size is not actually that size when you measure it's height? For example, a font set at size 24 pixels is actually only 16 pixels tall (cap height).

    Hello, indeed, as Semaphoric stated, the Em box is not the same as the Cap heigh...
    It is described in length in this blog post by Thomas Phinney http://www.thomasphinney.com/2011/03/point-size/
    THis article has good images also that illustrate the em square: Font Bureau Blog | The Em

  • Determining Video Pixel Size from Still Pixel Sizes

    Hello
    I posted a few questions here in regard to establshing good Pixel Sizes in stills for use in FCE.
    Tom, and Studio X were very helpful, and I picked up a few pointers.
    One thing I still didn't grasp completley was how to determine (perhaps from a simple formula), what the Video Pixel Size would be from a photo's pixel size.
    As Tom pointed out:
    "A 2400x3000 pixel image may be perfectly adequate and not produce as many imaging problems when scaled in a video application"
    And as I discovered in regard to print size:
    "An 8" x 10" document that is scanned at 300 dpi has the pixel dimensions of 2,400 pixels (8" x 300 dpi) by 3,000 pixels (10" x 300 dpi).
    So then all this being said, is there a way to easily determine what the Video Pixel Size will be from the given Pixel dimensions of a still image?
    (Like from a re-sized Tiff in Photoshop)
    My version of Photoshop doesn't seem to have that conversion option for determining NTSC Video image quality.
    Thanx
    Mike

    And if I need to zoom in really tight to a small area in a particular still, I should allow myself an image size a bit larger than 1280x720. Correct?< </div>
    If only it was that easy. The video screen is roughly 800 by 500 pixels. That's all there are. If you bring in a 1600x1000 JPEG (might want to try TIFF instead) and you wish to see the whole image, it will be scaled down to 25% to fit onto the small screen and all of your pixels will be thrown away or mashed together. It's terribly inefficient and the image gets mushily softened.
    If you need to zoom in to a particular spot on the image, imagine that spot as filling the 800x500 pixel screen. You can use a simple ruler and measure the area you wish to be full screen (without any scaling being applied by FCP because that will destroy your image). Now measure the largest part of the image that you want to be on screen at any one time when zoomed all the way out. The ratio of those two numbers is what you will need to scan. Example (highly simplified don't try to argue about the precision) if your big image is 10x8 inches and your desired tight shot is 4x3 inches, you must provide a TIFF that is 2.5 or 2.75 times the size of the tightest area. That tight area is going to be 800x500 pixels. You will scan the 10x8 image to obtain a TIFF that is almost 2.5 times 800 pixels wide or 2000 pixels, by 2.5 times 500 pixels high or 1250 pixels. Do not bother to convert that into DPI. You are targeting an image size measured in pixels. It's got nothing to do with the size of the original image or the DPI. Repeating: Absolutely nothing.
    This will give you an image into which you can zoom and suffer no image degradation. It will also give you a tremendous processing hit. FCP just doesn't like to do that kind of scaling.
    Umm, doesn't look like I helped much. This issue is highly misunderstood and it's quite confusing if you come from a Photoshop background. giving up concepts like DPI is almost impossible. The only way to get it is to work through the many options Photoshop and video people offer up and try to figure out why some of them don't work for you.
    bogiesan

  • When scaling in page setup, 1st page prints correctly, but subsequent pages do not scale correctly/too large for the paper, parts of the text missing

    When trying to print in Firefox, and when scaling the page size in page setup, the first page prints correctly, but subsequent pages do not scale correctly and are too large for the paper, with parts of the text are being cut off at the top and right. This is not fixed by checking or un-checking the "ignore scaling/shrink to fit page width" in the print window, or by changing the scaling%.
    I am running Firefox 15.0.1, on Mac OS 10.5.8.
    The same problem happens in the print preview and if I save the print as a .pdf
    I have tried all the fixes in the how to's and others in various forums with no improvement.
    This happens every time I try to print a document scaled up or down only in Firefox.

    The 2nd page print scaling error has been an issue with Firefox on the Mac since 2011. People at Mozilla have not considered this a major problem. Try printing anything at less than 100% and you'll quickly see how every page after the first page being scaled wrong gets old real fast. The lack of a solution to this issue forced me long ago into using Safari as my primary browser. Good luck waiting until version 21 for a solution. Current release is 18.0.2.

  • Why TextFrames does not get exactly specified size?

    Hi, I'm experiencing the following problem:
    when I create some TextFrames and specify size using this code below:
    Illustrator.CharacterStyle curStyle = curDok.CharacterStyles.Add("ColorText" + text.Id.ToString());
    charAttr.Size = Convert.ToInt32(text.Size * 2.5F);
    charAttr.TextFont = newFont;
    curTextFrame.Contents ="SOME TEXT";
    curTextFrame.Top = 200;
    curTextFrame.Left = 200;
    curTextFrame.Height = 1000;
    curTextFrame.Width = 2000;
    curStyle.ApplyTo(curTextFrame.TextRange, false);
    I get different TextFrames size, when I save image into some file format(I've tried .eps and pdf). For example, if I specife 2000 width of th frame and create few frames with different text, they all get different sizes, some of them becomes 2300 width, etc. Is this some type of scaling, or what?
    P.S. If you have some code(in any language), that creates TextFrames, and they get exactly specified size, please, post it here. Thank you.

    If you don't need to be able to edit the text here is some code that should work. Worked for me using CS2 and Visual C# 2008.
    Illustrator.Application ai = new Illustrator.Application();
    Illustrator.Document doc = ai.Documents.Add(AiDocumentColorSpace.aiDocumentCMYKColor, 100, 100);
    Illustrator.CharacterStyle curStyle = doc.CharacterStyles.Add("ColorText");
    Illustrator.TextFont textFont = ai.TextFonts["Arial-Black"];
    int textSize = 20;
    curStyle.CharacterAttributes.Size = Convert.ToInt32(textSize);
    curStyle.CharacterAttributes.TextFont = textFont;
    Illustrator.TextFrame curTextFrame = doc.TextFrames.Add();
    curTextFrame.Contents = "SOME TEXT";
    curStyle.ApplyTo(curTextFrame.TextRange, false);
    Illustrator.GroupItem textGroup = curTextFrame.CreateOutline();
    textGroup.Top = 200;
    textGroup.Left = 200;
    textGroup.Height = 1000;
    textGroup.Width = 2000;
    Hope this helps.

  • Exact pixel width in crop

    Is there any way to crop to an exact pixel width in Develop mode?
    I often need to crop to exactly 440 pixels (without enlarging or contracting content, so I can't do it in Export) and find I have to either do it in Photoshop or keep switching between Library mode (to see the size in pixels) and Develop mode (to guess a little bit more or a little bit less with the crop tool) - of course I can never achieve it exactly this way.
    Am I missing something? This seems like such a basic parameter for cropping, more so than aspect ratio, which is well respresented.

    I need exactly 440 pixels because that is the exact size that fits in my blog - a technical consideration and also very much a stylistic/publishing one, so that all the images on the blog are the same width. I imagine all layout artists must usually work to these kind of size constraints.
    As long as the image is large enough (in pixel terms) I can crop it "artistically" any way I like (eg 2534 x 1679 pixels) and then export it at 440 pixels width and that's fine. This is exactly what I do in many, indeed most, circumstances, and any half-decent photo will of course be larger than 440 in width, so no problem there.
    The problem arises when the subject matter (usually a distant bird) is smaller than 440 pixels width and yet I want to show as much detail as possible on my blog. It'll be a "record shot" usually of something quite uncommon for some reason - so I guess that would fall much more into the scientific or technical camp. Then I don't want to shrink the exported image at all as the subject matter is quite small enough already at full size. That's why I have to crop it to exactly 440 pixels wide (the height really doesn't come into it). Neither do I want to enlarge the image to 440 pixels as there's really no point and I'll end up with even blurrier pixels.
    I have a feeling that the general principle that lies behind this requirement must be very common. I have sometimes even sold images to the press where they needed a particular item, for which I only had a lousy shot but it was good enough for a drop-in about an inch across. OK, publishers won't be using Lightroom to do their image resizing (although why not?), but when I publish my blog I want to go through as few unnecessary steps as possible (don't we all…)

  • Cannot crop to an exact pixel dimensions

    I am having a hard time cropping to an exact pixel dimensions upon export.  For my work, I need to crop to exactly 2166X1600, with a tolerance of no more than one pixel off of those dimensions, i.e. 2166X1599. 
    I set crop tool to 2166X1600 and crop all of my images.  On the export I constrain to largest dimension of 2166 in both horizontal and vertical directions. Results vary widely from right on 2166X1600 to several pixels off on the short side.  Sometimes more than 1600, and sometimes less.  Any thoughts as to why these constraints do not work exactly?  Some sets of images I have to redo as many as 25% of a gallery of 200-300 images.  Any thoughts?  Thanks!

    See, I don't need to crop the original image to 2166X1600.  I need a finished image at 2166X1600.  Meaning, in theory I should be able to crop an image to 1:1.35375 ratio, which is 2166X1600, and export to constrain to 2166 on the longest side.  When it's constrained to 2166, the short side should always be 1600.   
    Here's where the problem is...  When you set the crop window to 2166X1600, you expect that when you size your crop on your image that the only options for the boundary are multiples of 2166X1600.  In reality, the crop visual boundaries are approximate.  Here's an example...
    I have an image that I have cropped to a finished size of 3185X2350.  Which is based upon a 2166X1600 crop.  When I export it, I need the 3185 to become 2166.  So the long side is constrained to 2166, and it is reduced by a factor of 1.47.  3185/2166=1.47  If I reduce the short side, 2350, by that same factor of 1.47 you end up with a short side of 1598.  Which is why I have a problem.
    My invalid assumption was that when you set specific pixel dimensions in the crop tool, that only those values would be shown in the crop tool's bounding box.  Photoshop can do it...

  • Is there a way to determine pixel size of type displayed in browser?

    I'm still wrestling with getting type to line-break as I see it in Dreamweaver.
    At 'Actual Size' in Safari, the type is bigger than I see it in Dreamweaver. I have determined that 12px is the appropriate size while working in Dreamweaver but when I view the text online it is much bigger and the line-breaks do not fall where the writer wants them to.
    Here is the page in question:
    http://www.kgngroup.net/logos_and_packaging.html
    I guess I was wondering first, if there is a 'sizeometer' that can identify the actual pixels size of type as it is displayed, so I can tell how much bigger it actually is than what I am trying to build.
    TIA,
    Ken

    pziecina wrote:
    Hi
    The size of your text is set to 100% in your body elements css, this means that for Safari you will get a default font size of 16px, (providing you have not changed the browsers default settings).
    Change the body element font-size to 12px in the css and see what happens.
    PZ
    www.pziecina.com
    I've run out of helpful stars to hand out to all of you nice people. Thank you so much, and as the post quoted here also demonstrates, there are 'overrides' in CSS. It struck me this morning as I have been thinking about this, the very first thing to introduction to CSS is that the meaning of Cascading Style Sheets is that there is an order of priority in command, and the troops closest to the front lines get the final say. I would think that the statement in the document would be the final word, but apparently it's the CSS sheet that takes priority in this case.
    I think my thinking has been in reverse on this rule, not unusual for me, but now I need to re-educate myself thanks to this problem.
    Ken

  • Exporting Versions to a specific pixel size

    I want to export files for a slideshow that requires a pixel size of 1900 x 1200 , can it be done in Aperture ? , I have tried modifying the export preset , it does not work with (Fit Within ) is there another way ?
    Thanks
    Ray

    Trythis,
    What exactly is failing?
    Your 1900x1200 size is a very strange size. That's not the 3:2 aspect ratio of an SLR or the 4:3 aspect ratio of point-and-shoot cameras. Also, Aperture will not enlarge pictures by choosing "fit within", since a smaller picture already "fits within". I.e., if you have a 640x480 picture, that already "fits within" 1900 pixels so Aperture will not make it bigger.
    Also, Aperture will not crop your pictures on export. You may have to crop each picture first so that it has a 19:12 aspect ratio, and then "fit within" 1900 pixels. If the aspect ratio of a picture is 19:12 and the picture is larger than 1900 pixels, Aperture should properly reduce the size to 1900x1200, based on the aspect ratio.
    nathan

  • Is there a way to adjust the pixel size/resolution of a picture in iPhoto?

    Hi there!
    Long story long, I have downloaded a photo from a friend's not-so-great camera in order to make it into a blanket that is 50x60 in size.  When I try to upload the picture, the website that I'mbuying it through says that in order for it to look good it should be 9300x7800 pixels.
    I think one is 2265x2168 if I'm looking at the right place in iPhoto, on the photo information.  Is it possible and if so, how can I beter the resolution in order to create this gift for someone?
    Thanks for any and all help...hope I supplied enough information to even warrant an answer.  I'm new the Mac computers & still learning what I can/can't do!

    Answer is simple - that is not possible
    You can use programs like PhotoShop Elements to makeup new pixels and put them between the existing pixels- but the quality of the resulting image will be lower than the original even though it has more pixels
    And you might ask the print firm for suggestions since no comsumer camera has images that come close to 9300 x 7800 - You would be hard pressed to get an image that size without a $25,000 or more pro camera - for example a $15,000 Canon EOS 1Dc is only 4096x2160 pixels - http://snapsort.com/learn/sensor/pixel-size
    LN

Maybe you are looking for

  • I can't "clear list" in the download box with the latest Firefox browser on any of my computers.

    When I download a PDF or any file with firefox, the download box will appear like normal tracking the download until it's finished. Usually when the download is complete, you can click on "clear list" in the bottom left of the box to clear your downl

  • Data Execution Prevention error

    I updated itunes on my computer and now everytime i try and start up itunes it gives me a Data Execution Prevention window, saying it will not allow itunes to start because it is protecting my computer.  I am running Windows XP Service pack 3.  My Qu

  • How to activate both connected monitor

    In my application, i have to connect 2monitors with the CPU and have to activate both connected monitors(means both should show windows) PRASHANT SONI SOFTWARE ENGINEER-LabVIEW

  • How to add another new report painter in existing T-code?

    HI, Can someone guide me, how to add a report painter report ZAL into a existing T-code? My T-code contain 2 report, now i wish to add a new one. So when user execute this T-code, we can see these 3 report. Thanks

  • Tomcat problem with form based login

    Hi, I have a page for form-based login, but the problem is that the image and css files dont load on the login page request. What I gather from other discussions is that this is because these are still protected when the page is requested. How do I e