Use PhantomJS’s page.clipRect property to crop the area that page.render() rasterizes. Assign an object containing top, left, width, and height before rendering. Keep page.viewportSize separate: it controls the browser-like layout viewport, while clipRect controls the rectangle saved in the image or PDF.
This complete workflow creates a page, sets both dimensions, opens the URL, and saves only the selected 400-by-300 region:
var page = require('webpage').create();
page.viewportSize = {
width: 1024,
height: 768
};
page.clipRect = {
top: 14,
left: 3,
width: 400,
height: 300
};
page.open('http://example.com/', function() {
page.render('capture.png');
phantom.exit();
});
Run the file with the PhantomJS command-line application. The resulting PNG contains the rectangular region beginning 3 pixels from the left and 14 pixels from the top of the rendered page, with a width of 400 and a height of 300.
What clipRect controls
The official API describes clipRect as the rectangular area of the web page rasterized when page.render is invoked. It is an object, not a CSS selector or a DOM element reference.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute#1 Best Overall
The four properties
top: the vertical starting offset of the capture rectangle.left: the horizontal starting offset.width: the rectangle’s horizontal size.height: the rectangle’s vertical size.
All four values belong in the object assigned to page.clipRect. A missing or malformed property does not express the rectangle you intended, so use numeric values and verify the dimensions before opening and rendering.
What happens when clipRect is omitted
If you do not set page.clipRect, page.render() processes the entire web page. That is useful for a normal page capture, but it is not a crop. To capture a smaller region, set the rectangle explicitly before calling page.render.
clipRect versus viewportSize
These properties solve different problems and are commonly confused:
| Property | Purpose | When to set it | Effect on the output |
|---|---|---|---|
page.viewportSize |
Sets the dimensions PhantomJS uses for page layout, simulating the window size of a traditional browser. | Before opening the URL, when the page must lay out at a particular width and height. | Changes responsive layout, line wrapping, and the coordinate space in which the page is rendered. |
page.clipRect |
Selects the rectangular area rasterized by page.render. |
Before rendering, normally before opening as part of the capture setup. | Limits the saved image or PDF to the specified rectangle. |
For a predictable result, set both. Choose a viewport that produces the layout you need, then choose a clip rectangle within that rendered coordinate space. Changing only the viewport can reflow the page; changing only the clip rectangle changes the captured bounds.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
A reliable PhantomJS clipping workflow
- Create the page. Load the
webpagemodule and callcreate(). - Set the viewport. Include both
widthandheightinpage.viewportSize. - Set the crop. Assign
top,left,width, andheighttopage.clipRect. - Open the target URL. Perform the navigation with
page.open. - Render the file. Call
page.render(filename)from the open callback. - Exit PhantomJS. Call
phantom.exit()after rendering so the command-line process terminates.
Keeping the setup before navigation makes the intended layout and capture area explicit. Rendering inside the page.open callback follows the documented workflow, so the page is opened before the file is written.
Complete examples
Capture a fixed card-sized region
This script uses a 1,280-by-900 layout viewport and captures a 640-by-360 rectangle beginning at coordinate (120, 180):
var page = require('webpage').create();
page.viewportSize = { width: 1280, height: 900 };
page.clipRect = {
top: 180,
left: 120,
width: 640,
height: 360
};
page.open('https://example.com/', function() {
page.render('card.png');
phantom.exit();
});
The viewport determines how the site lays itself out. The output file is restricted to the 640-by-360 rectangle.
Render the full page
Remove the clipRect assignment when you want PhantomJS to render the entire page rather than a crop:
Free tools Windows power users keep installed
One-click scans. No signup required.
Rank #3
var page = require('webpage').create();
page.viewportSize = { width: 1024, height: 768 };
page.open('http://example.com/', function() {
page.render('full-page.png');
phantom.exit();
});
Choose an output format by filename
page.render saves to the filename you provide. PhantomJS selects the output format from the extension unless a format is specified. Documented formats include PNG, JPEG, BMP, PPM, and PDF. GIF support depends on the Qt build used by PhantomJS. For example:
page.render('region.png');
page.render('region.jpg');
page.render('region.pdf');
Use one render call per desired file. The clip rectangle applies to each render invocation made with that page.
Coordinate and sizing decisions
Start with the layout you need
Decide the browser-like window size first. A narrow viewport can trigger a mobile layout, while a wide viewport can keep navigation and columns on one line. Set viewportSize with both dimensions before page.open; otherwise you may capture a layout different from the one you intended.
Then define the crop
Use top and left to place the rectangle, and width and height to define its size. If you want the top-left portion of a page, use small offsets. If you want a lower section, increase top while keeping the viewport large enough for that page layout.
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Keep layout and capture requirements separate
A 400-by-300 screenshot does not require a 400-by-300 viewport. You might need a 1,024-by-768 viewport to preserve a desktop arrangement and still capture only a 400-by-300 area. Conversely, enlarging the clip rectangle does not make a responsive page lay out at a wider viewport; change viewportSize for that.
Troubleshooting clipRect captures
The file contains the whole page
- Confirm that
page.clipRectis assigned beforepage.render. - Check the property name and capitalization: it is
clipRect, with a capital R. - Ensure the assignment is made on the same
pageobject that performs the render.
The crop is the wrong size
- Check
widthandheightin the clip object rather than inviewportSize. - Remember that the viewport controls layout; a responsive reflow can make the content appear different even when the crop dimensions are unchanged.
- Print or review the values in your script before rendering to catch a unit or arithmetic mistake.
The content appears in an unexpected location
- Review
topandleft; they position the capture rectangle in the rendered page coordinate space. - Verify the viewport dimensions. A different viewport can move content because the page uses a different layout.
- Make sure you are opening the URL before rendering, as in the documented callback pattern.
The output format is not what you expected
- Use the intended extension in the filename, such as
.png,.jpg, or.pdf. - Do not assume GIF works on every installation; GIF support depends on the PhantomJS Qt build.
The process does not finish
Call phantom.exit() after page.render in the open callback. The official example exits immediately after writing the capture.
Performance and reliability considerations
clipRect specifies what is rasterized; it does not replace navigation or page setup. PhantomJS still opens the target page before page.render runs. Keep the rectangle no larger than the area you actually need to reduce the amount of output data, but choose the viewport for the layout rather than trying to use the crop as a substitute for it.
For repeatable captures, keep the viewport and clip values in named configuration variables, use the same output extension for a batch, and render only after the page.open callback fires. If a page must be captured at several sizes, create a clear pair of values for each layout and crop rather than changing one property and assuming the other follows it.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Best Value
Or skip the browser setup
If you need an HTTP screenshot service instead of maintaining a PhantomJS script, ScreenshotNeo returns a screenshot or PDF from one request. Its cleaner capture workflow accepts cookie and consent banners before the shot and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the result with X-Page-Verdict and X-Billed headers. It also provides an MCP server for Claude, Cursor, and other MCP clients through take_screenshot, get_page_info, and capture_pdf.
See the ScreenshotNeo API documentation for the complete parameter list. A basic request is:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
The same request in Python:
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
open("shot.webp", "wb").write(r.content)
And in Node.js:
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo supports full-page captures with lazy images loaded, CSS-selector element capture, dark mode, device presets or custom viewports, retina scale, PDF paper and page-range controls, custom CSS and JavaScript, clicks before capture, hidden selectors, waits for selectors, delays or network idle, request and resource blocking, custom headers, cookies, user agents and Authorization, timezone and geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Parameter names used by other screenshot APIs also work.
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots, and every feature is available on every plan. Create a free ScreenshotNeo account to get started.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallQuick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

