Solved

Maximum Image Size On Front Page

Posted on 2010-11-10
7
466 Views
Last Modified: 2012-05-10
http://www.tornadoeskick.com

I am wondering if a code exists to resize images on the front page so that they fit within the column widths. I do not use the media uploader in WP. Instead, I upload my images to image folders within my site and link using the standard IMG command.

The front page displays the entry in a two column layout that is smaller than my standard image size (700px). However, single article pages do not have the sidebar and thus expand the content area to accommodate the images.

Is there a code I can add to the front page file that will resize any images bigger than 500px to a set size (i.e. 500px)?

Thanks all!
0
Comment
Question by:laubacht
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 23

Expert Comment

by:jeremyjared74
Comment Utility
I am not positive I completely understand all of your requirements. I will start off by providing a link to an article which I believe addresses what you are asking for. Let me know if I am wrong, and I will look again.

LINK: http://soulsizzle.com/wordpress/adding-additional-image-sizes-to-wordpress-themes/
0
 
LVL 15

Accepted Solution

by:
AndyBeard earned 334 total points
Comment Utility
The easy way is to just use CSS and rely on a browser to do a sufficient job of rendering the image.

The programming solution would be to use something like http://code.google.com/p/timthumb/

You could then write some javascript/jquery that would modify each image URL and pass it to timthumb

Alternatively if you uploaded smaller versions each time, you could just use some javascript to modify image src.
0
 
LVL 1

Author Comment

by:laubacht
Comment Utility
Thanks guys, I am going to give both options a look and test them out..

Jeremy, basically what I am going for is a resize on the front page to fit the column width.  Since I run my images through a program that resizes, renames, and watermarks all my images, I upload them via standard FTP to a directory in my site to which I store them and call them via IMG SRC commands to post into pages.  With that said, I do not use the media tools supplied by Wordpress.  The issue is my standard resize is 700px wide; my front page column for an article is only 500 pixels wide.

If you go to my website (http://www.tornadoeskick.com), you'll notice that the images in the first entry spill out on the right cause they are too big.  However, if you open up the single article page which has no sidebar (and thus is only one column), it'll fit fine.

What I want to do is make it so any articles displayed on the front page automatically resize my image to a specified size (or percentage) so it'll fit on the front page.  But if a user opens the single article, it will display as normal.

Its hard to make sense of this, but that's something I hope makes sense.

Below is a code sample I found today...

So something like that perhaps?

To better give a visual, go to my front page at http://www.tornadoeskick.com/ and scroll down to the first article titled "First Snow Of 10/11 Season".  Notice how the image of the three cars with the snow falling is too big for the column (its 700px by default) and thus spills out on the right side.  If you display the article on its own (via http://www.tornadoeskick.com/2010/11/4236), it fits fine given the lack of the sidebar.

What I want to do is make it so images being displayed on the front page automatically get displayed with a smaller width so they fit, but then display like normal when on its own.

Does that help a bit?

Thanks again guys!
.rt-article-content img {
       max-width:100%;
       height:100%;
}

Open in new window

0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 8

Assisted Solution

by:Sam Cohen
Sam Cohen earned 166 total points
Comment Utility
If the wordpress theme is already coded to show the image..look for that code and just add width="500" or style="width:500px;" to the image tag of the loop...do not add a height attribute
0
 
LVL 8

Expert Comment

by:Sam Cohen
Comment Utility
or if you want to use instead ...
just add height="500" or style="height:500px;" to the image tag of the loop...but DO NOT add a width attribute
0
 
LVL 15

Assisted Solution

by:AndyBeard
AndyBeard earned 334 total points
Comment Utility
The css route is really easy... though much easier if just one of those nested DIVs, or just a unique class was applied to all your historical photos.

then you could just add this to your CSS

.home .imghome {max-width:500px;}

You could use that aligncenter if it isn't used for anything else anywhere.

That being said it will squish things.

Probably the best solution possible is to create a shortcode

We can grab a shortcode from this post
http://www.jauhari.net/resize-images-using-shortcode-with-timthumb.jsp

// Image resize in content
function timmyimg($atts, $content = null) {
      extract(shortcode_atts(array(
            'w' => '540',
            'h' => '250',
            'class' => 'alignnone',
            'alt' => ''
      ), $atts));
      return "<img src='". get_bloginfo('template_directory') . "/timthumb.php?src=".$content."&w=".$w."&h=".$h."' alt=".$alt." class='wp-post-img ".$class."' />";
}
add_shortcode('img', 'timmyimg');


Then modify it with a is_singular conditional to return an unmodified width.

thus something like

if is_singular {

return "<img src='" . $content . "' alt=".$alt." class='wp-post-img ".$class."' />";

} else

return "<img src='". get_bloginfo('template_directory') . "/timthumb.php?src=".$content."&w=".$w."&h=".$h."' alt=".$alt." class='wp-post-img ".$class."' />";
}


I am sure there are some bugs in that but you will get the idea. (I just tinker with code)
0
 
LVL 1

Author Comment

by:laubacht
Comment Utility
So the trick was to modify my template.css file to include the lines of code below.. this adjusted the images displayed onthe front to a max size of 600px, maintain the aspect ratio of the original image, but display the image normally on the single post pages.
.rt-article-content img {
	max-width:600px;
	height:100%;
}

Open in new window

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Transferring a wordpress site from a host or local dev server to another host can be a pain. So I've included my steps on how I have accomplished this task. Steps include an assumption that you have Cpanel access or Ftp access.. If you do not hav…
WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now