• I am trying to make all inserted images in post content render at a specific image_size.
    I’ve looked into get_image_tag and add_filter, but I can’t figure where (?functions.php) I should create the code, and how to make it work for <img>’s in certain pages (e.g., single.php) .

Viewing 12 replies - 1 through 12 (of 12 total)
  • Resize the images using CSS.

    Thread Starter rucativava

    (@rucativava)

    That is one way, the wrong one in my opinion.
    I want it to happen server side, while wp renders the page, and uses its crunched images in the add_image_size() i created in funtions.php .

    Thread Starter rucativava

    (@rucativava)

    Thank you for the link. I’ve been there already, and I’ve been using these add_image_size() thoroughly in my template when I know the ID of the attachment.

    What I need to know is how to make all images in a post be output with a specific image size in the course of the_content().

    If the images have been inserted into the content directly, you cannot change their size except via CSS.

    Thread Starter rucativava

    (@rucativava)

    That is a real pitty, that you cannot manipulate the content of the_content(). Neither with filters or such?

    if this is only for presentation purposes how about resizing it through javascript? have you looked into that? or is this constant image dimensions a requirement for some other function and php cropping it is the only way?

    Thread Starter rucativava

    (@rucativava)

    I want to use the wordpress crunched images because it is the most optimized way in terms of size (kb). Javascript and CSS might present two problems:
    1 – If the given image in the_content() is smaller, I’ll get a blurred bigger one.
    2 – If the given image in the_content() is bigger, I’ll waste bandwidth and memory.
    Since WordPress is a CMS that handles resizing images, isn’t it normal to be able to use these kind of functionality?

    With Javascript, you can calculate the images width and height and return a size of your liking, though if the image size you desire is bigger than that of the original image used, it wouldn’t look as sharp, but not really blurry or pixelated (this is only the case if you force the size to a dimension bigger than the orig through CSS/Javascript).

    Also, some clarifications. WP already has “Media Settings” where you can specify the default “Thumbnail Size/Medium Size/Large Size” which you can use before inserting the image to the TinyMCE (the WordPress WYSIWYG editor).. This is probably what you need. Specify the image dimension you want then before you insert it in the editor, select that dimension..

    Lastly, the “the_content()” function is already a prepared function used to echo the “post_content” column for the particular post requested. We can’t really do much with this since it is only pulling prepared data from the db and presenting it – meaning the data (image) in this case is already cropped etc.

    The only reason I can think of why you want to resize images without using the built-in WP feature is if you want all the prior published posts that does not have the dimensions you want resized. Is this the case?

    Thread Starter rucativava

    (@rucativava)

    I am using WordPress as a CMS for this project. Posts will work as containers of information on specific products. My client needs to alternate some images with text – the post editor is perfect for this; but I want to override possible mistakes made by him regarding chosen image size. That is why I need to override the output image_size with the one I already created through add_image_size(‘post-width’,750,500).

    Enter this in your functions.php:

    update_option('thumbnail_size_w', 'SIZE_YOU_WANT');
    update_option('thumbnail_size_h', 'SIZE_YOU_WANT');
    update_option('medium_size_w', 'SIZE_YOU_WANT');
    update_option('medium_size_h', 'SIZE_YOU_WANT');
    update_option('large_size_w', 'SIZE_YOU_WANT');
    update_option('large_size_h', 'SIZE_YOU_WANT');

    *replace the ‘SIZE_YOU_WANT’ with the thumbnail size you desire.

    Now what happens with this is that we have set both the width and height for all sizes and that WP will crop the image based on this specs. WP still calculates the image’s best cropped size so that it will appear proportional (e.g. if you specify 100 as the size, you might get a dimension like 97px by 100px depending on the orientation of your image) but it won’t exceed the value you entered.

    -Raby

    Thread Starter rucativava

    (@rucativava)

    Raby:

    I think we’re on the right track. That is what I want. Some kind of function that will override what is written in the post. From what I understand, your code will override any image dimensions with the given ‘SIZE_YOU_WANT’ dimensions.
    Do you know how can I limit this update_option() to a specific part of my .php file? e.g.: single.php main loop.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Output images in specific image_size’ is closed to new replies.