Search code examples
image-scalingwordpress-3.9

How do you scale images to 60% in Wordpress 3.9?


In previous versions of Wordpress images could be automatically scaled to 60% with one click. Now in Wordpress 3.9 the only automatic scaling is Thumbnail, Medium, and Full Size. I could chose Custom Size or drag it to the approximate size I want, but Custom Size requires me to compute 60% myself and dragging it is inexact.

All of my images are different heights and widths. They are images of a written font so the font size needs to be the same for every image, even though the height and width are different. In the past I just made all of my images display at 60%. Is there a way to do that in Wordpress 3.9?


Solution

  • Since I couldn't find a better long term method, I just wrote some Java code to do the job. This way I can just cut and paste from the HTML view.

    import java.util.Scanner;
    
    public class ImageResizer {
    
    public static void main(String[] args) {
    
        Scanner userInput = new Scanner(System.in);
        String inputString;
        String outputString;
    
        System.out.print("Default resize is 60%\n");
        System.out.print("Type \"exit\" to quit: \n\n");
    
        do {
            // input something like: 
            // width="208" height="425"
            System.out.print("Enter html: ");
            inputString = userInput.nextLine();
            outputString = resize(inputString);
            System.out.print(outputString + "\n");
    
        } while (!inputString.equals("exit"));
    }
    
    public static String resize(String myString) {
    
        final int RESIZE_PERCENT = 60;
    
        // parse input string
        String delims = "[ ]+"; // spaces
        String[] tokens = myString.split(delims);
        for (int i = 0; i < tokens.length; i++) {
            if (tokens[i].startsWith("width") || tokens[i].startsWith("height")) {
                // extract the height/width number
                String subDelims = "[\"]"; // quote mark
                String[] subTokens = tokens[i].split(subDelims);
                int number = Integer.parseInt(subTokens[1]);
                number = number * RESIZE_PERCENT / 100;
                // rebuild string
                tokens[i] = subTokens[0] + "\"" + number + "\"";
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < tokens.length; i++) {
    
            sb.append(tokens[i]);
            if ((i + 1) < tokens.length) {
                sb.append(" ");
            }
        }
        return sb.toString();
    }
    }