Hi all; In a folder i have my main images ,i need some code in php that read all images from folder and resize it without squash or strech with php and put the resized images in a destination folder.
Thanks
Hi all; In a folder i have my main images ,i need some code in php that read all images from folder and resize it without squash or strech with php and put the resized images in a destination folder.
Thanks
Resize both width and height by a percent:
newwidth = width * percent%
newheight = height * percent%
If you need a given width newwidth for example, then calculate the percent of newwidth/width*100, and calculate the height based on the resulting percent, as above.
Open your image with ImageCreateFromJPEG, create a new empty image with ImageCreateTrueColor and copy the content with ImageCopyResampled from the original image to the new image. You can save it then with imageJPEG. Like this:
<?php $imageInfo = getImageSize( 'image.jpg' ); $imageWidth = $imageInfo[0]; $imageHeight = $imageInfo[1]; $thumbWidth = round( $imageWidth / 2 ); $thumbHeight = round( $imageHeight / 2 ); $gdImage = imageCreateFromJPEG( 'image.jpg' ); $gdThumb = imageCreateTrueColor( $thumbWidth, $thumbHeight ); // thumbnail size here imageCopyResampled( $gdThumb, $gdImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imageWidth, $imageHeight ); imageJPEG( $gdThumb, 'image_thumb.jpg', 80 ); imageDestroy( $gdImage ); imageDestroy( $gdThumb ); ?>