Service to resize images uploaded to a WordPress site

2

I have a WordPress site which has a bigger headache for resizing images, and I think a PHP script that resizes images is not the solution for me.

Every publication involves about 3 images, it is very tiring to create multiple resizing; is there any web site that allows me to upload the photos and choose the width size, eg width: 250px ?

When I send an image to put as highlight it gets the original resolution, if it is a 4,000px x 2,000px image it will get very heavy. I do not need an image of this size, what I want is just to reduce the resolution of the image (pixels), thus making the images getting light.

Or is there a WordPress plugin that will help me with something?

    
asked by anonymous 08.06.2014 / 06:56

3 answers

4

According to the comments described in the question, I understood the problem and I think an interesting solution is to use ImageMagick, because of that I created this answer.

There is an ImageMagick port for Windows and can be downloaded here:

ImageMagick for Windows

Some of ImageMagick's advantages over any Web service are:

  • It runs locally. There is no risk that the images in question stop at search engines. Remember that these web services receive your image, do the rendering (probably with ImageMagick or similar) and return a processed image. There are no guarantees that the images stored there can not one day stop at search engines such as Google, etc. This same principle applies to the famous PDF to DOC converters, etc; Therefore, if the file to be converted is confidential, never use any web service.

  • Local processing tends to be faster, as these services are generally free to run on powerful servers;

  • You can perform processing on a batch of images (for example, a folder with multiple JPGs). Very useful when you want to upload your images to Picasa, for example. You reduce to 1600x1200, which makes uploading faster;

  • The program should be used by command line, see some examples below:

    mogrify -resize 1600x1200 *.jpg
    

    The above example resizes all files in the current folder to the resolution of 1600x1200. Note that the files after being processed will have the same name as the original (the files will be lost). Therefore, ensure that the command will not run on the original files.

    mogrify -path imgs/ -resize 800x600 *.jpg
    

    The command above will reduce the files of the current folder to 800x600 resolution, however, the processed files will be saved in the imgs folder (which, in the case above, must be inside the current folder). Thus, there is no risk that the original files will be modified.

    There are several other options on the command line and this is one of the great advantages of ImageMagick.

    Some examples of using ImageMagick More Examples

        
    09.06.2014 / 01:49
    3

    Two good online tools that do this are Quick Thumbnail and ResizeImageOnline .

        
    08.06.2014 / 13:17
    1

    A plugin is pretty easy :

    <?php
    /**
     * Plugin Name: (SOPT) Substituir Imagens Originais
     * Description: Substitui imagens originais (full size) pelo tamanho "grande" na hora do upload. 
       Ajuda a economizar espaço em disco, já que uma foto de 3240x4320 (5MB) pode se converter
       em uma de 768x1024 (108KB - exemplo depende do ajuste em /wp-admin/options-media.php e da qualidade jpeg). 
     * Author: brasofilo
     * Plugin URI: https://wordpress.stackexchange.com/a/54059/12615
     */
    
    add_filter( 'wp_generate_attachment_metadata','replace_uploaded_image_wpse_48882' );
    add_filter( 'jpeg_quality', 'qualidade_jpeg_sopt_19538' );
    
    /**
     * Replace original by largest size on upload
     * 
     * @author brasofilo
     * @wp_hook wp_generate_attachment_metadata
     * 
     * @param object Image information
     * @return object
     */
    function replace_uploaded_image_wpse_48882( $image_data ) 
    {
        // if there is no large image : return
        if ( !isset( $image_data['sizes']['large'] ) ) 
            return $image_data;
    
        // paths to the uploaded image and the large image
        $upload_dir              = wp_upload_dir();
        $uploaded_image_location = $upload_dir['basedir'] . '/' . $image_data['file'];
        $large_image_location    = $upload_dir['path'] . '/' . $image_data['sizes']['large']['file'];
    
        // delete the uploaded image
        unlink( $uploaded_image_location );
    
        // rename the large image
        rename( $large_image_location, $uploaded_image_location );
    
        // update image metadata and return them
        $image_data['width']  = $image_data['sizes']['large']['width'];
        $image_data['height'] = $image_data['sizes']['large']['height'];
        unset($image_data['sizes']['large']);
    
        return $image_data;
    }
    
    /**
     * Qualidade: de 0 a 100
     */
    function qualidade_jpeg_sopt_19538() 
    {
        return 75;
    }
    

    You can also set JPEG quality advanced and use a custom size:

    add_image_size( 'new-large', 1600, 1200 ); /* definido em functions.php ou num plugin */
    
    • changing all occurrences of $image_data['sizes']['large'] by $image_data['sizes']['new-large'] .
    10.06.2014 / 20:16