About this article
This article was created using an automated generation workflow powered by generative AI. Operations, observations, and limitations were organized by referencing official documentation and fixed code from educational materials.Verification status: Partial cross-checking with official information and implementations. Browser behavior for the pinned version has not been verified.
Landscape banners and square thumbnails retain different areas of the same photo. Compare them by changing the aspect ratio and position of the crop frame.
Key terms to know first
Aspect ratiois the proportional relationship between width and height.
Cropis the process of extracting a portion of an image.
Thinking with a Quadrant Diagram
Compare compositions for different use cases across two axes. Positions serve as examples for decision-making.
quadrantChart
title 構図を決めるときの比較例
x-axis 縦長 --> 横長
y-axis 背景を狭く --> 背景を広く
正方形カード: [0.5, 0.36]
横長バナー: [0.87, 0.65]
縦長サムネイル: [0.22, 0.31]
Operating the Live Demo
Crop using 1 and 1.7778. Drag the frame to change its position as well.
How to Interpret the Results
The retained area changes even for the same photo.
The provided image contains text outside the center. Move the frame to the center and the left edge to see what is retained at the same aspect ratio.
Key Points of the Code
Change the aspect ratio of the selection and output the cropped image, matching the API version in use.
The implementation can be checked in the Implementation Code section of the demo screen.
When using in production
When creating thumbnails, check whether text and subjects are cut off even in small viewports.
Comparing square and landscape frames
The initial value is 1. Executing this is expected to display a 480×250 sample image and a cropping frame. Adjust the position of the frame and click the crop button to add the selected area image to a separate display field. First, select near the center and check how much of the text and shapes from the original image remain. Next, change the input to 1.7778 and run it. The newly created frame will be approximately 16:9 landscape. Observe how it differs from a square frame when centered on the same subject.
| Input | Meaning of the ratio |
|---|---|
| 1 | Square |
| 1.7778 | Approximately 16:9 |
| 0 or abc | Implementation default of 1 |
The operation to change the crop position is separate from changing the ratio. Even if you change to a landscape format, the desired image may not be obtained if the subject is not in the center of the screen. Move the frame from the center to the edge for comparison. Pressing the run button again destroys the previous Cropper instance and recreates the experimental image and frame. If you want to compare outputs under the same conditions, record the results before re-running.
Distinguishing aspect ratio from pixel count
Aspect ratio is width divided by height. For example, 160×90 and 320×180 have different pixel counts but the same ratio. Selecting a composition suited to the purpose and adjusting to the image size required by the distribution destination are separate tasks. This demo specifies the selection frame ratio using aspectRatio. Since getCroppedCanvas is given maxWidth:480 and maxHeight:400, it sets an upper limit on the output, but does not strictly guarantee 480×400. The actual crop size depends on the selection area and other factors. If precise delivery dimensions are required, design both the ratio and the output size.
The implementation uses Cropper.js 1.6.2. In this version, you can create a Cropper instance from an image element and render the selected area using getCroppedCanvas. Do not mix APIs from newer versions directly. This tutorial material uses toDataURL on the generated canvas to display the result on the screen. It is not a practical photo editing app with file selection or dedicated download features. It is a tutorial designed to help users understand ratios and composition using provided fictitious images.
If the frame does not appear in the expected position
Reset the input to 1 and verify that the image loads successfully. If the image is not visible, check for loading errors, successful fetching of JavaScript modules and CSS, and image decoding. If the frame does not move outside the image, also check the viewMode constraints. If the input ratio is 0 or non-numeric characters, the implementation falls back to 1, so it does not necessarily result in an error display. Extremely large values and the like must be restricted to ratios permissible for business use.
In actual thumbnail creation, the policy is to save it as a separate file without overwriting the original image. Cropping to a horizontal banner may cut off people's heads or text, so check the finished image even at a small display width. Whether the cropped image suits the purpose cannot be judged solely by the bounding box values. When adding an implementation to draw external images onto a Canvas, CORS conditions may prevent retrieving the output. Also verify the image source and usage rights.
The sample images in the public demo are fictitious. For systems using actual photographs, verify reflections, location data, portrait rights, and copyrights before sharing. The cropping operation alone does not resolve all privacy issues related to the image.
Verification Scope
The course-specified version is Cropper.js 1.6.2. Reference execution of numeric processing with the same aspect ratio as the implementation using Node.js 22.16.0. 1->1, 1.7778->1.7778, 0->1, abc->1. Cropper.js core and Canvas output unexecuted. CDN acquisition, license pinned version verification, and actual display are to be checked separately.
References
Official API and Documentation(Accessed November 30, 2026)
