---
title: resolution_utils
---

<div class="python-reference">
<a id="fastvideo.models.dits.hyworld.resolution_utils-functions"></a>
<a id="fastvideo.models.dits.hyworld.resolution_utils"></a>

<h2 id="fastvideo.models.dits.hyworld.resolution_utils.generate_crop_size_list"><code>fastvideo.models.dits.hyworld.resolution_utils.generate_crop_size_list</code></h2>
<pre class="doc-signature"><code>generate_crop_size_list(base_size = 256, patch_size = 16, max_ratio = 4.0)</code></pre>

<h2 id="fastvideo.models.dits.hyworld.resolution_utils.get_closest_resolution"><code>fastvideo.models.dits.hyworld.resolution_utils.get_closest_resolution</code></h2>
<pre class="doc-signature"><code>get_closest_resolution(image_height, image_width, target_resolution = &#x27;480p&#x27;)</code></pre>
<p>Get closest supported resolution for given image dimensions.</p>
<h3>Parameters</h3>
<dl>
<dt><code>image_height</code></dt><dd><p>Height of input image</p></dd>
<dt><code>image_width</code></dt><dd><p>Width of input image  </p></dd>
<dt><code>target_resolution</code></dt><dd><p>Target resolution string (e.g., "480p", "720p")</p></dd>
</dl>
<h3>Returns</h3>
<dl>
<dt><code></code></dt><dd><p>tuple[int, int]: (height, width) of closest supported resolution</p></dd>
</dl>
<details><summary>Source</summary><pre><code>def get_closest_resolution(image_height, image_width, target_resolution=&quot;480p&quot;):
    &quot;&quot;&quot;
    Get closest supported resolution for given image dimensions.

    Args:
        image_height: Height of input image
        image_width: Width of input image  
        target_resolution: Target resolution string (e.g., &quot;480p&quot;, &quot;720p&quot;)

    Returns:
        tuple&#91;int, int&#93;: (height, width) of closest supported resolution
    &quot;&quot;&quot;
    config = TARGET_SIZE_CONFIG&#91;target_resolution&#93;
    bucket_hw_base_size = config&#91;&quot;bucket_hw_base_size&quot;&#93;
    bucket_hw_bucket_stride = config&#91;&quot;bucket_hw_bucket_stride&quot;&#93;

    crop_size_list = generate_crop_size_list(bucket_hw_base_size, bucket_hw_bucket_stride)
    aspect_ratios = np.array(&#91;round(float(h) / float(w), 5) for h, w in crop_size_list&#93;)

    # Find closest aspect ratio
    image_ratio = float(image_height) / float(image_width)
    closest_idx = np.abs(aspect_ratios - image_ratio).argmin()
    closest_size = crop_size_list&#91;closest_idx&#93;

    return closest_size&#91;0&#93;, closest_size&#91;1&#93;  # (height, width)</code></pre></details>
<h2 id="fastvideo.models.dits.hyworld.resolution_utils.get_resolution_from_image"><code>fastvideo.models.dits.hyworld.resolution_utils.get_resolution_from_image</code></h2>
<pre class="doc-signature"><code>get_resolution_from_image(image_path, target_resolution = &#x27;480p&#x27;)</code></pre>
<p>Automatically determine resolution from input image.</p>
<h3>Parameters</h3>
<dl>
<dt><code>image_path</code></dt><dd><p>Path or URL to input image</p></dd>
<dt><code>target_resolution</code></dt><dd><p>Target resolution tier ("480p", "720p", etc.)</p></dd>
</dl>
<h3>Returns</h3>
<dl>
<dt><code></code></dt><dd><p>tuple[int, int]: (height, width) matching HY-WorldPlay's bucket selection</p></dd>
</dl>
<details><summary>Source</summary><pre><code>def get_resolution_from_image(image_path, target_resolution=&quot;480p&quot;):
    &quot;&quot;&quot;
    Automatically determine resolution from input image.

    Args:
        image_path: Path or URL to input image
        target_resolution: Target resolution tier (&quot;480p&quot;, &quot;720p&quot;, etc.)

    Returns:
        tuple&#91;int, int&#93;: (height, width) matching HY-WorldPlay&#x27;s bucket selection
    &quot;&quot;&quot;
    # Handle URL inputs
    if isinstance(image_path, str) and image_path.startswith((&#x27;http://&#x27;, &#x27;https://&#x27;)):
        response = requests.get(image_path)
        response.raise_for_status()
        img = Image.open(BytesIO(response.content))
    else:
        img = Image.open(image_path)
    img_width, img_height = img.size
    return get_closest_resolution(img_height, img_width, target_resolution)</code></pre></details>
</div>
