tagsport.blogg.se

Resize image php upload
Resize image php upload













resize image php upload

I have found some good answers on the forum and have put them in together and finally created a Class which resizes an image. Imagettftext($this->img, $font_size, $this->angle, $hcenter+1, $vcenter-2, $this->whitetr, $this->font, $this->string) Īlso I have been using the accepted answer but it does not keep the ratio in some cases. Imagettftext($this->img, $font_size, $this->angle, $hcenter, $vcenter, $this->blacktr, $this->font, $this->string) $hcenter = round((imagesx($this->img) - $box) / 2 ) While ( ($box img)) & ($box img)) & ($font_size max_font_size) ) $box = $this->calculateTextBox($this->string, $this->font, $font_size, $this->angle) If($mime='image/jpg' || $mime='image/jpeg' || $mime='image/pjpeg') It will scale down or up an image to the maximum width or height function createThumbnail($image_name,$new_width,$new_height,$uploadDir,$moveToDir) $moveToDir - Directory to save the resized image $uploadDir - Directory of the original image $new_height - Height of the resized photo (maximum) $new_width - Width of the resized photo (maximum) These are the parameters it needs: $image_name - Name of the image which is uploaded I've copied it below, might need a bit of tinkering! (It does required the GD library)

RESIZE IMAGE PHP UPLOAD CODE

I had written a peice of code like this for another project I've done. 160 x 236 (rounded) is the correct answer. We do the math according to the solution proposed by PHP.net: It is better (as it maintain the aspect ratio), but it exceeded the maximum accepted width. The next solution proposed is the following: if($old_x < $old_y) Let's do some math taking the accepted solution: if($old_x < $old_y) Let's say we have an image of 1630 x 2400 pixels that we want to be auto resized keeping the aspect ratio to 160 x 240. There are other answers (with examples) on stackoverflow to similar questions (the same question formulated in a different manner) that suffer of the same problem.

resize image php upload

Please note the relevant lines from the example given on PHP.net website: $ratio_orig = $width_orig/$height_orig Any calculation should reflect this difference. The reason is simple: there will be cases when the ratio of the source image and the ratio of the destination image will be different. Actually the accepted solution it is not the correct solution.















Resize image php upload