Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:01:18+00:00 2026-06-13T13:01:18+00:00

WordPress uses a function to center completely the image on a thumbnail when you

  • 0

WordPress uses a function to center completely the image on a thumbnail when you are editing a post so it look like this when i´m editing the post:

enter image description here

i´m trying to show the image that way on a wordpress page but I don´t know how to create a function like the one that uses wordpress to do that:

$s_x = floor( ($orig_w - $crop_w) / 2 );
$s_y = floor( ($orig_h - $crop_h) / 2 );

So this is how it looks in my page:

enter image description here

it just shows from the top, so it cuts the image, no center or resize

this is my markup:

            echo '<div class="aimagediv" >'; //        
            echo '<img src="'.$s['project_image'].'" alt="" width="270" />';
            echo '</div>';

i´m limiting the width just to show something, i know it´s wrong to do it that way, that´s why i´m looking for a function to rezise and center the image over the div.

Can someone help me with this one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:01:19+00:00Added an answer on June 13, 2026 at 1:01 pm

    I think you’re better to put this image as a background image of the div and then using css to change background-size to cover and then background-position to center…

    HTML

    echo '<div class="image" style="background-image:url(\''.$s['project_image'].'\');">';
    
    echo '</div>';
    ?>​
    

    CSS

    .image{
    width: 270px;
    height: 270px;
    background-size:cover;
    background-position: center;
    }​
    

    Here’s a jsfiddle showing it in action:

    http://jsfiddle.net/Jhu2Y/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that uses 5.3 feature anonymous function ( https://github.com/JeffreyWay/Easy-WordPress-Custom-Post-Types/blob/master/jw_custom_posts.php ), but
Wordpress uses hooks and actions for extensibility. A plugin might look something like this:
I have developed a wordpress plugin that uses jquery. This plugin have some javascript
I'm trying to create a website that allows for easy theme adding/manipulation like wordpress
I'm using WordPress and I'm trying to write a plugin that uses a file
I've created a Wordpress theme that uses several custom page templates. As per the
I am writing a WordPress plugin that uses WP_HTTP for making an API call.
I have a Wordpress theme that uses MooTools and jQuery. I use jQuery noConflict
I'm working on a WordPress site that uses a dynamically generated menu system which
I would like to create a plugin that uses the contact form 7 hook,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.