How to deal with wordpress images?

Passing explicit dimensions to those APIs won’t give you an image with those dimensions unless one already exists. It will choose the image size that’s closest.

So, you have 2 options

  1. Add a named image size via add_image_size that matches the desired dimensions. WordPress will generate an image of this size on upload. You will need to use a regenerate thumbnails type plugin to apply this to past uploads
  2. Refactor your CSS to use object-fit: cover; then use a larger image size, then specify the width and height of the image explicitly ( which you should be doing anyway instead of relying on the image dimensions to determine the img elements width and height. The advantage of this is that images that are smaller, larger images, and images with different aspect ratios, will all work just fine.

e.g.

...yourfeaturedimg... {
    width: 458px;
    height: 355px;
    object-fit: cover;
}

I recommend option 2 as it’s more performant, easier to test, and involves following the HTML spec. It also makes your theme more robust and able to handle images better.

Further reading: