Hot answers tagged image-resize
5
No, it won't create a new image that is exactly the same size.. nor should it. All the thumbnail, medium, and large images are resized images, by definition. Since the original image is already 600x600, there's no point in creating another file at the same size, but with a lower quality (remember that JPEG compression is lossy).
However, if you specify in ...
5
Basically you just retrieve the info via getimagesize(), a basic PHP function, a then handle your errors with notes.
The plugin
A basic plugin as a starting point:
<?php
/** Plugin Name: (#67107) »kaiser« Restrict file upload via image dimensions */
function wpse67107_restrict_upload( $file )
{
$file_data = getimagesize( $file );
// Handle ...
4
I'd try saving it as a PNG 24 first.
If that doesn't work have a look at these:
http://www.akemapa.com/2008/07/10/php-gd-resize-transparent-image-png-gif/
http://stackoverflow.com/questions/6382448/png-transparency-resize-with-simpleimage-php-class
4
Take a look at Otto's Dynamic Image Resizer plugin
This plugin changes the way WordPress creates images to make it
generate the images only when they are actually used somewhere, on the
fly. Images created thusly will be saved in the normal upload
directories, for later fast sending by the webserver. The result is
that space is saved (since ...
4
i guess you are looking for this
add_attachment
and
delete_attachment
example:
add_action('add_attachment', 'attachment_manipulation');
function attachment_manipulation($id)
{
if(wp_attachment_is_image($id)){
//do your own tasks
}
}
4
To built on Max Yudin's answer you should use the intermediate_image_sizes_advanced filter, and not image_size_names_choose.
function add_image_insert_override($sizes){
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
}
add_filter('intermediate_image_sizes_advanced', 'add_image_insert_override' );
Another easier ...
3
Adding a post thumbnail is pretty easy, open content.php, if you're using excerpts on your homepage find this
<?php the_excerpt(); ?>
then add this just above that line
<?php the_post_thumbnail('thumbnail', 'class=alignleft'); ?>
If you're not using excerpts add it above
<?php the_content( __( 'Continue reading <span ...
3
WordPress and TimThumb both use GD to resize images, so quality is going to be similar. GD's resize quality is not as good as Photoshop, you'll notice this especially in fine details.
Both WP and TimThumb can be modified to use ImageMagick, WP via a plugin, TimThumb I think requires you edit the code directly, which is not ideal. ImageMagick will give ...
3
There's a lot going on here. First off, you should store the repeater field image as an ID (that probably requires changing how the subfield's setting and possibly re-uploading some of your images) and then use all the WordPress Core API functions to handle it. (You'll probably cross paths with wp_get_attachment_image_src.) That gets rid of your regex-ing, ...
3
You can perform a combination of things to accomplish a smaller file size. Let me guide you through it.
Firstly, you could add custom image sizes and adjust the dimensions to the very smallest for their purpose. Put the following in your functions file:
function my_insert_custom_image_sizes( $sizes ) {
// get the custom image sizes
global ...
3
If I remember right you have to unset all the defaults and add the new Size there:
<?php
function mxdCustomImageSizes($sizes) {
unset( $sizes['thumbnail']);
unset( $sizes['medium']);
unset( $sizes['large']);
unset( $sizes['full'] );
$myimgsizes = array(
'full-size' => __( 'Full Size' )
);
if( !empty($sizes) )
...
2
You can set up your own error handler, that either ignores the errors or outputs them in comments in the feed. Let it depend on the "surrounding" configuration, so if WP_DEBUG is false, ignore the errors. If it is true, output them in XML comments at the end of the feed, so you don't start a comment when you are in the middle of a tag.
If notices are ...
2
it can be caused by multiple reasons , some of which may be :
theme disabling this function
=> switch to default theme and check function again
GD library not installed on server
=> check your PHP server settings .
the image you are inserting is smaller than the thumbnail image size
set in Admin/Settings/Media.
=> check your default image sizes ...
2
In Advanced Custom Fields the field editing screen where you add in the required fields and assign them to post edit screens did you choose image URL or Attachment ID for the image field? It sounds like you've got it set as image URL which will just return the URL to the originally uploaded file as you've discovered.
On the Advanced Custom Fields website ...
2
I don't know if this is the best way to do this, but it works for me.
In the functions.php of the theme you are using, put this:
function remove_img_src($html)
{
$html = preg_replace('@(width|height)="([0-9])+" ?@i', '', $html);
return $html;
}
add_filter('image_send_to_editor', 'remove_img_src', 10, 8);
It uses regular expresions to change the ...
2
i'm looking for a more discrete and automatic approach. And that is altering the wp_create_thumbnail i think.
And that is where you'd be wrong. Here is the entire code for wp_create_thumbnail() from core:
function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) {
if ( !empty( $deprecated ) )
_deprecated_argument( __FUNCTION__, ...
2
If you need the images to be the same width but varying heights (ie not 300 x 300 but 300 x anything) then in settings -> media add 9999 to the height of whichever image size you want to use.
You can also define your own custom thumbnail using the same principle: http://codex.wordpress.org/Function_Reference/add_image_size
[EDIT] As @brasofilo suggests, ...
2
Here's my take on it
<?php
/**
* Plugin Name: Deny Giant Image Uploads
* Description: Prevents Uploads of images greater than 3.2MP
*/
function tomjn_deny_giant_images($file){
$type = explode('/',$file['type']);
if($type[0] == 'image'){
list( $width, $height, $imagetype, $hwstring, $mime, $rgb_r_cmyk, $bit ) = getimagesize( ...
2
WordPress doesn't regenerate the newly registered size, only applies it to future uploads.
You'll have to use something like the Regenerate Thumbnails plugin or one of the similar ones available at WordPress.org.
1
if what you need is to apply this to big images (no thumbnails like in Gembel's solution) you can use CSS, including a max-width statement. For example:
.content img{width:98%; max-width:200px;}
of course you should adapt the numbers to what you need, but you'll get the idea
1
According to this stackoverflow question, there is a program called imagemagick that might do this for you server side but it would probably be outside of WordPress. Otherwise, it looks like you have to shrink every frame and then put it all back together.
1
Custom Image Sizes
Resizing without cropping is already part of the core functionality, via add_image_size().
Note the last parameter:
<?php add_image_size( $name, $width, $height, $crop ); ?>
The Codex entry describes the $crop parameter as follows:
$crop
(boolean) (optional) Crop the image or not. False - Soft proportional crop mode ; ...
1
You can use the native Wordpress image_resize function to scale up images. Wordpress provides a hook called "image_resize_dimensions" which you can use to overwrite the default cropping settings. Here is a modified function which will support scaling up:
function image_crop_dimensions($default, $orig_w, $orig_h, $new_w, $new_h, $crop){
if ( !$crop ) ...
1
I believe your issue is that the value set for the global $content_width variable (which is 640px in Boilerplate and 584px in Twenty Eleven) is less than the width you're specifying via Settings -> Media.
WordPress is overriding your user setting with the Theme-specific value. This actually makes sense, since a Theme knows its maximum content width, and ...
1
Looks like you can do it with image captions, but not images at present:
From the wp-hackers mailing list:
I've got a filter I use that forces captions to be responsive on the
frontend. Definitely cuts down on the headaches.
Gist here: https://gist.github.com/2243601
Drew
1
When you upload an image, it's saved, and a copy is created for every image size, resized to the appropriate dimensions.
When you specify a set of dimensions manually, e.g.
wp_get_attachment_image_src($id, array(57, 57))
the 57x57 dimensions are compared to the image sizes, and the nearest image size is chosen and that image is returned. So for that to ...
1
Looking at your code, it looks like the file wil be looked for in .../wp-content/uploads/bill.jpeg. You'll need to include the yyyy/mm as well. I would use this:
require_once(ABSPATH . '/wp-admin/includes/media.php');
require_once(ABSPATH . '/wp-admin/includes/image.php');
$file = 'http://www.mysite.org/uploads/uploaddir/2012/02/bill.jpeg';
# Function ...
1
http://codex.wordpress.org/Function_Reference/image_downsize
Returns:
(bool|array) False on failure, array on success. Array with image url, width, height, and whether is intermediate size, in
that order is returned on success is returned. $is_intermediate is
true if $url is a resized image, false if it is the original.
I am going to assume the ...
1
I can save you hours searching on the internet to solve this problem.
Make sure you do this when adding a PNG to WordPress
png must be png 24 bit
If you are adding a logo to your WordPress site make sure the size of the logo is the exact size of what is already there.
If the size of the png is too big it makes the transparent background go black.
1
An extremely simple way is to make a Child Theme of the theme that you want to use, and still use Get the Image in the functions.php file of that child theme.
You should probably be doing this anyways if you are editing any files in the theme. It makes it super easy to upgrade commercial and public themes.
Only top voted, non community-wiki answers of a minimum length are eligible
