php resize thumbnail to fixed dimensions - no crop - php

I want to resize an image to a fixed size of 400x300.
I do not want to zoom crop it, I simply want the image constrained to either the width 400 or height 300 (depending on orientation), the image centered, and the rest of the image filled with black.
Does anyone know of a library/code that does this? (for GD)
Thanks,
Wesley

GD or ImageMagick can easily do this for you.
Create a new image with a black background of the desired height, then copy from the original, and place in the new.
Perhaps another answer will come along with the full code, but this will get you started. If not, I will post code for you later.

Related

Best way to scale an image if it's too small like pinterest does?

How does pinterest rescales their images? Even if you upload a 16x16 icon, it will rescale it but make it look smooth.. Does anyone know how they how their resize mechanism works?
The example you provided looks like they simply set the height of the image to be the height of the container, i.e. in the height attribute of the <img> tag. I wouldn't say it looks smooth at all, plus the aspect ratio is obviously way off.
But if you want to resize images in PHP yourself, there are several image libraries like GD. Take a look at the imagecopyresampled function (there is some example code on that page) or search for some tutorials.

PHP image resize ratio issue

Php thumb resize image based on provided width and height, I am working on profile image which is: 130x130
While users are uploading image of long heights(rectangle) which leads to strecthed image in its width and when uploading long width image(rectangle) then strecthed, I hope you understand what I mean. Because when anyone uses a large square image it resize to correct 130x130 but longer width and height get strecthed.
I am thinking of having a good suggestion or idea to work around such images, either crop them from top to make them perfect square first.
Thanks,
Najm.
Usually you will take the longer side, scale it up and scale the shorter side by the same percentage. One such snippet is here. You can also prefill the canvas with a smooth background that fits with your overall design.

Darken part of an image using GD

I've got a jpg image and I want to return the same image, with a "highlight" effect.
Basically, I want to pass the script the xy coords, and redraw the image darkened, with an ellipse that remains in the original colouring.
Initially I did this by creating a second image, same dimensions, and drawing a white elipse, then merging them together at 40% or so. The effect works, but the "highlighted" area is obviously a bit washed out.
Anyone know how I can basically delete that ellipse so it is purely transparent and then merge it on top of the original for a clear highlight?
You can use a png for the second image with the elipse being completely transparent while the area that you want darkened has an alpha of 20% (or whatever works best). When you merge the images, you can use imagecopy instead of imagecopymerge as the alpha (transparent) value is included in the second image already.

Picture Size problems in HTML when working is screen resolutions

I'm running a small application which has an 70% width, and 90% height value, as the rest of the screen is menus.
In this space I need to echo images which isn't problem, but if the image is too big it creates an overflow. If have fixed properties for the image depending on what the images' original size is, it will destroy the quality or look of the image. Can someone tell me how it is possible to echo the image without overflowing or destroying the images quality?
Something along the lines of how Facebooks image viewer works.
Don't constrain both width and height then.
Constrain one or the other and let the browser resize the image according to its ratio. If you tell the browser to resize your 100x100 image to 60x2, it's going to look terrible, no matter what. But if you tell your browser to resize your image to height 60, it will automatically make the width 60 to keep the image's proportions, and it won't be distorted.
If you want to go with an image gallery, you can. Here's one that looks similiar to facebook's from a quick google : http://phpimagegallery.com/

phpThumb - change watermark size

I'm using phpThumb in a script to clean my images and add a watermark to them. We have images of very different sizes (from 100px width to 800px), so no matter what watermark image I use, it's either going to look too small or too big on the image.
Do you know of a way to tell phpThumb to resize the watermark? Or is there a way to resize the watermark image (depending on size of image being watermarked)?
Thanks a lot guys!
Ali
I am facing the same issue.
Maybe you could put some if statements in the phpthumb.config file in the DEFAULT PARAMETER SECTION
then depending on the height and width parameters you can decide to use different files with varying sizes for the watermark.
make sure you change $PHPTHUMB_DEFAULTS_GETSTRINGOVERRIDE to false
This is not perfect cause you could not know the source image size to start with.
but it would be a better fit based on the parameters passed to phpthumb.
I guess the only other solution would be to use phpthumb as an object but that would require a lot of work.

Categories