Support » Developing with WordPress » Scaling up small images and cropping to specific (exact size)

  • Tim Trott



    I need to be able to scale up a small image to a custom image size so an exact crop can be made. I can’t find a plugin or code example that does this, can anybody help?

    Let’s say I upload an image 400×200. I have added add_image_size('featuredImage', 650, 300, true); and currently I get a 650×300 image, but it only contains the 400×200 image top left and the rest is black. What I need is the uploaded image upscaled to 650×325 and the crop taken from that. Original should not be altered.

    It needs to play well with Regenerate Thumbnails and Manual Image Crop.

    I think it needs to hook into wp_generate_attachment_metadata but I don’t know how to do that.

    Can somebody help please?


Viewing 3 replies - 1 through 3 (of 3 total)
  • This is what everyone always wants to avoid doing. When you scale up, where would the extra resolution come from? Typically, the algorithm is to double all the pixels. So if you choose a size that is not double the original, which pixels do you treat differently?
    I have read this article about a workflow that produces good images by upscaling 20% more than the desired size and then going down to that size, but it works because it is using particular tools in Photoshop.
    Those tools are not built-in to PHP, although there are image tools, I don’t think all sites have them installed by default.

    Thread Starter Tim Trott


    Thanks Joy. I’m not too worried about quality, to me its more important to have correctly sized images which do not break layouts or have ugly borders.

    My point wasn’t about quality. It was about how the algorithm actually creates a larger image from a smaller one. PHP doesn’t have that built-in. You have to have the right graphics library to get some functions, and not all servers have that.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Scaling up small images and cropping to specific (exact size)’ is closed to new replies.