Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

Fit selection to screen or zoom to selection

Community Beginner ,
Mar 31, 2024 Mar 31, 2024

Hi there

I have searched all I could (community, chat GPT), etc to find an answer but it seems there is no such feature? Can it be?

 

I have an active selection, moving around zooming in, etc. How do I fit the screen so that all selected areas are visible and fill the screen? When adjusting the selection on a portion of an image, it would be helpful to be able to zoom out again to the entire selection.

 

Maybe I just missed it somehow. Thanks for the help.

TOPICS
macOS , Windows
3.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 31, 2024 Mar 31, 2024

The following script leverages the fit layers on screen command, offering a single history state.

 

/*
Zoom to Selection Bounds.jsx
v1.0, 1st April 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/fit-selection-to-screen-or-zoom-to-selection/td-p/14526195
*/

app.activeDocument.suspendHistory("Zoom to Selection", "main()");

function main() {
    var selectionBounds = null;
    try {
        selectionBounds = app.activeDocument.selection.bounds;
        if (sele
...
Translate
Adobe
Community Expert ,
Mar 31, 2024 Mar 31, 2024

Just so you know, ChatGPT and Gemini are often wrong - don't rely on them for answers. You have all of the commands under the veiw menu, do none of them work for you? 

Melissa Piccone | Adobe Trainer | Online Courses Author | Fine Artist
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 31, 2024 Mar 31, 2024

Thank you for your hint, you are right: I was advised to use CMD+0 by ChatGPT but this just zooms out to the Canvas. Select a rectangle in any project and try and Zoom to it. I was not able to find a solution. The one that gets closest is "fit layer on screen", but then this applies to a layer, not a selection.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2024 Mar 31, 2024

I use a trackpad, zooming in and out is something I don't have to think about and is automatic with pinching. With  a mouse, I prefer the keyboard shortcut using the spacebar + cmd/ctrl and clicking and dragging - you can also set up a scroll wheel - it's in the preferences. 

Melissa Piccone | Adobe Trainer | Online Courses Author | Fine Artist
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2024 Mar 31, 2024

@rslosiar 

 

I’ll create a script for you to zoom to the selection. I'll post back later when I have time to look at this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2024 Mar 31, 2024

Photoshop recently added the View > Fit Layer(s) on Screen command and its keyboard shortcut, which may cover at least some of your situations. If what is selected (in the Layers panel) are one or more type or shape layers, or pixel layers with transparent areas, then you can already zoom any of those to fit the window. And another shortcut for that is to Option/Alt-click the layer in the Layers panel.

 

What that command doesn’t cover is fitting a marquee (pixel) selection to the window. Hopefully Stephen Marsh’s script will take care of that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2024 Mar 31, 2024

The following script leverages the fit layers on screen command, offering a single history state.

 

/*
Zoom to Selection Bounds.jsx
v1.0, 1st April 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/fit-selection-to-screen-or-zoom-to-selection/td-p/14526195
*/

app.activeDocument.suspendHistory("Zoom to Selection", "main()");

function main() {
    var selectionBounds = null;
    try {
        selectionBounds = app.activeDocument.selection.bounds;
        if (selectionBounds) {
            executeAction(stringIDToTypeID("copyMerged"), undefined, DialogModes.NO);
            pasteInPlace();
            reselect();
            fitLayersOnScreen();
            app.activeDocument.activeLayer.remove();
        } else {
            // There should be a selection active to zoom to the selection!
        }
    } catch (e) {
        alert("Error!" + "\r" + e + ' on line: ' + e.line);
    }
}


function pasteInPlace() {
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    descriptor.putBoolean(s2t("inPlace"), true);
    descriptor.putEnumerated(s2t("antiAlias"), s2t("antiAliasType"), s2t("antiAliasNone"));
    descriptor.putClass(s2t("as"), s2t("pixel"));
    executeAction(s2t("paste"), descriptor, DialogModes.NO);
}

function fitLayersOnScreen() {
    function s2t(s) {
        return app.stringIDToTypeID(s);
    }
    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("menuItemClass"), s2t("menuItemType"), s2t("fitLayersOnScreen"));
    descriptor.putReference(s2t("null"), reference);
    executeAction(s2t("select"), descriptor, DialogModes.NO);
}

function reselect() {
	function s2t(s) {
		return app.stringIDToTypeID(s);
	}
	var descriptor = new ActionDescriptor();
	var reference = new ActionReference();
	reference.putProperty( s2t( "channel" ), s2t( "selection" ));
	descriptor.putReference( s2t( "null" ), reference );
	descriptor.putEnumerated( s2t( "to" ), s2t( "ordinal" ), s2t( "previous" ));
	executeAction( s2t( "set" ), descriptor, DialogModes.NO );
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 01, 2024 Apr 01, 2024

Thanks to you all! I am really overwhelmed by your support! Many great thanks Stephen for the script. I will study how to install scripts and try it out shortly.  

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 01, 2024 Apr 01, 2024

Stephen are you sure that after we install your script and activate it, the screen won't dissolve and says APRILS FOOL!  I have been searching the forum for such a jest, and am disappointed that I haven't found one so far.  😉

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 01, 2024 Apr 01, 2024
quote

Stephen are you sure that after we install your script and activate it, the screen won't dissolve and says APRILS FOOL!  I have been searching the forum for such a jest, and am disappointed that I haven't found one so far.  😉


By @Trevor.Dennis

 

Unfortunately, the doctors had to remove my sense of humour due to an unfortunate mishap.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 01, 2024 Apr 01, 2024

Do you use the spring loaded H key shortcut?  Simply hold down the H key (no modifier) and the screen zoom out to 'fit Image' with a rectangle showing the current zoom size.  You move the rectangle with the mouse, and when you release the H key, it will zoom to the new loaction at the previous zoom ratio.  It's not exactly what you describe, but might be a workaround for you.  I know I love it and use it all the time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 10, 2025 Feb 10, 2025

Just had a go at creating a tool for this exact problem as i've become used to the 'Fit To Selection' type tools of 3d software like Blender and Solidworks etc. 

function zoomToSelection() {
    if (!app.documents.length) {
        alert("No document open.");
        return;
    }

    var doc = app.activeDocument;

    if (!doc.selection.length) {
        alert("Please select at least one object.");
        return;
    }

    var selectionBounds = doc.selection[0].visibleBounds; // Get the bounds of the first selected object
    for (var i = 1; i < doc.selection.length; i++) {
        var objBounds = doc.selection[i].visibleBounds;
        selectionBounds = [
            Math.min(selectionBounds[0], objBounds[0]), // Left
            Math.max(selectionBounds[1], objBounds[1]), // Top
            Math.max(selectionBounds[2], objBounds[2]), // Right
            Math.min(selectionBounds[3], objBounds[3])  // Bottom
        ];
    }

    // Add margin (increase bounding box by a percentage)
    var marginFactor = 3; // 200% margin
    var width = selectionBounds[2] - selectionBounds[0];
    var height = selectionBounds[1] - selectionBounds[3];

    var marginWidth = width * marginFactor;
    var marginHeight = height * marginFactor;

    // Center view
    var centerX = (selectionBounds[0] + selectionBounds[2]) / 2;
    var centerY = (selectionBounds[1] + selectionBounds[3]) / 2;

    // Determine zoom level
    var zoomFactor = Math.min(doc.width / marginWidth, doc.height / marginHeight);

    // Apply zoom and center view
    doc.activeView.zoom = zoomFactor;
    doc.activeView.centerPoint = [centerX, centerY];
}

zoomToSelection();
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 10, 2025 Feb 10, 2025

This was a GPT assist btw

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 12, 2025 May 12, 2025

I hate that when I click option and select a layer it zoomes in on the object of the layer when I'm trying to simply select a path from that layer. I always have to zoom out now. Very annoying feature. Can I disable this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2025 May 12, 2025
LATEST

It's a "feature" they added a few years ago - I agree, hate it. I don't know of anyway to disable it. 

Melissa Piccone | Adobe Trainer | Online Courses Author | Fine Artist
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines