focal_point - how to use?

Hey,

Wondering if anyone can help? I am looking to use focal point in a new section i am building and just cant seem to get it to center to the focal point.

I have checked the image and there is a focal_point, and it is passing the following as a inline style. Theme is Dawn

object-position:41.8602% 50.1944%;

Section looks like this:


  {% if section.settings.title != blank %}
    ## {{ section.settings.title }}
  {% endif %}

  {%- style -%}
    .custom-grid {
      display: grid;
      grid-gap: 20px;
      grid-auto-rows: var(--card-height-mobile);
      grid-template-columns: repeat({{ section.settings.columns_mobile }}, 1fr);
    }

    @media screen and (min-width: 750px) {
      .custom-grid {
        grid-auto-rows: var(--card-height-desktop);
        grid-template-columns: repeat({{ section.settings.columns_desktop }}, 1fr);
      }
    }

    .custom-grid__item {
      position: relative;
      overflow: hidden;
    }

    /* Forces the image to fill its container entirely */
    .custom-grid__image {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    .custom-grid__overlay {
      position: absolute;
      padding: 0.5rem;
      color: #fff;
      font-size: 1.2em;
      text-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
      pointer-events: none;
    }

    .custom-grid__overlay--bottom_left {
      bottom: 10px;
      left: 10px;
    }
    .custom-grid__overlay--bottom_center {
      bottom: 10px;
      left: 50%;
      transform: translateX(-50%);
    }
    .custom-grid__overlay--bottom_right {
      bottom: 10px;
      right: 10px;
    }

    .custom-grid__link {
      display: block;
      text-decoration: none;
      color: inherit;
    }

    .section-custom-grid__title {
      text-align: center;
      margin-bottom: 20px;
      font-size: 2em;
    }

    .section-custom-grid {
      padding: 20px;
    }
  {%- endstyle -%}

  
    {% for block in section.blocks %}
      

        {% if block.settings.link != blank %}
          
        {% endif %}
          {% if block.settings.image != blank %}
            {{ block.settings.image
               | image_url: width: 1500
               | image_tag: 
                   alt: block.settings.alt_text, 
                   class: 'custom-grid__image', 
                   width: nil, 
                   height: nil, 
                   sizes: '(min-width:750px) 100vw, 100vw',
                    object-fit: cover
            
            }}
          {% else %}
            {{ 'detailed-apparel-1' | placeholder_svg_tag: 'placeholder-svg' }}
          {% endif %}
        {% if block.settings.link != blank %}
          
        {% endif %}

        

          {{ block.settings.heading }}
        

      

    {% endfor %}
  

{% schema %}
{
  "name": "Custom Grid Section",
  "settings": [
    {
      "type": "text",
      "id": "title",
      "label": "Section Title",
      "default": "Custom Grid Section"
    },
    {
      "type": "range",
      "id": "columns_desktop",
      "label": "Columns on Desktop",
      "min": 1,
      "max": 6,
      "step": 1,
      "default": 3
    },
    {
      "type": "range",
      "id": "columns_mobile",
      "label": "Columns on Mobile",
      "min": 1,
      "max": 4,
      "step": 1,
      "default": 1
    },
    {
      "type": "range",
      "id": "card_height_mobile",
      "label": "Card Height (Mobile) (px)",
      "min": 50,
      "max": 600,
      "step": 10,
      "default": 200
    },
    {
      "type": "range",
      "id": "card_height_desktop",
      "label": "Card Height (Desktop) (px)",
      "min": 50,
      "max": 600,
      "step": 10,
      "default": 200
    }
  ],
  "blocks": [
    {
      "type": "grid_item",
      "name": "Grid Item",
      "settings": [
        {
          "type": "image_picker",
          "id": "image",
          "label": "Image"
        },
        {
          "type": "text",
          "id": "alt_text",
          "label": "Alt Text",
          "default": "Image description"
        },
        {
          "type": "url",
          "id": "link",
          "label": "Link URL (page, collection, etc.)"
        },
        {
          "type": "text",
          "id": "heading",
          "label": "Overlay Heading",
          "default": "Overlay Heading"
        },
        {
          "type": "select",
          "id": "overlay_position",
          "label": "Overlay Position",
          "default": "bottom_left",
          "options": [
            {
              "value": "bottom_left",
              "label": "Bottom Left"
            },
            {
              "value": "bottom_center",
              "label": "Bottom Center"
            },
            {
              "value": "bottom_right",
              "label": "Bottom Right"
            }
          ]
        },
        {
          "type": "color",
          "id": "overlay_background_color",
          "label": "Overlay Background Color",
          "default": "#000000"
        }
      ]
    }
  ],
  "presets": [
    {
      "name": "Custom Grid Section",
      "category": "Custom",
      "blocks": [
        {
          "type": "grid_item"
        },
        {
          "type": "grid_item"
        },
        {
          "type": "grid_item"
        }
      ]
    }
  ]
}
{% endschema %}

@Chris_Sydney If you notice my image shopify normally used the focal point in dawn theme. I my image I set which are I want to show. shopify then supplied that area and image show from that area. Hope you understand.

thats awesome, how do you deal with the liquid on this?

feel like i am missing something? sorry not understanding what you mean exactly.

In the css code in your file this class is handle the object location objec-fit:cover and then the custom style added by shopify imag tag for the image focal.

/* Forces the image to fill its container entirely */
    .custom-grid__image {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

Thanks, but still a little lost. I thought you needed object-fit: cover within containers?

https://shopify.dev/docs/storefronts/themes/architecture/settings/input-settings#image-focal-points

whats the best solution to solve it then?

Cheers

CB

Please check this line in above doc
Using image_tag, if a focal point was provided, then an object-position style is added to the image tag, with the value set to the focal point.
The image cover object fit will be set in the image tag. not the container. Because which style the image will fit depend on that class name
.custom-grid__image { object-fit: cover; }

object-position is definitely being provided on the image.

object-position: 41.8602% 50.1944%;

and is loading onto the

but is not centering on the focal point (which is the stone in this)

appreciate any ideas (first time using focal points so getting quiet confused (but curious none the less as would prefer to natively using focal points) or suggestions to make it work.

Thanks!

Please go to shopify file image area and click one image then then adjust your own focal point like this image , based on that it adjust the focal point attribute by image tag. you do not need to adjust the possition

Sorry if it was confusing, the image-position was from selecting the focal point on the image. which is where i am currently at.

@Arif_Shopidevs

wondering if you had any other ideas?

@Chris_Sydney

After many investigate and checking what I have figure out that shopify focal point do not center the image at that point. depending of image size and width and the area it fill up it adjust the the image possition of top or left or right this way so that focal point area almost cover in that case it is not fully centered the are.

if i got any more information I will try to share with you

Thank you

@Arif_Shopidevs

I think you are right, mearly focal_point just serves are a guide (bit annoying).

still looking into it, as I would much prefer to select image of mismatched size and then center to the focal point (it is better for ecommerce managers).