I am uploading image with PHP.
During upload i am resizing image from actual image to needed size.
But image size in not getting in its aspect ration according to width.
PHP Code.
$size = getimagesize($_FILES["file"]["tmp_name"]);
$ratio = $size[0]/$size[1];
$req_width = 500;
$height = $req_width* $ratio*2;
//after this code for re-size image with above dimension and upload image code.
What i am doing wrong in formula.
Why are you multiplying it by 2? And where does $width come from?
You should just be able to divide the required width by the ratio to give you the correct result.
$height = $req_width / $ratio;
Related
I have an image with an aspect ratio of 9x16 (337px, 600px). I want to change the image 16x9 (1066px, 600px) permanently without cropping images using PHP
this is the example that i want before and after.
Im Sorry i dont code yet because i don't know what i suppose to type to type on Google
$imagemal = "https://myanimelist.cdn-dena.com/images/anime/1933/97061l.jpg";
list($width, $height, $type, $attr) = getimagesize("$imagemal");
$newwidth = $height/9;
$newwidth = $newwidth*16;
$newwidth = round($newwidth);
I've finally been able to complete the script for an multiple image resizer, currently it's resizing the original image into 3 other sizes, but I am unable to figure out how to set the original height and width. I have used the getimagesize() but it does not seem to work.
The whole code is here but I don't think it's necessary to post all of it here. http://pastebin.com/UR75tdj3
I have done the following to set each of the images height and width I'd like them to resize into.
$uploadedfile = $_FILES['file']['tmp_name'];
list($width,$height)= getimagesize($uploadedfile);
#large
$largeWidth = 670;
$largeHeight = 330;
$largeTmp = imagecreatetruecolor($largeWidth, $largeHeight);
#medium
$mediumwidth = 330;
$mediumheight = 330;
$mediumTmp = imagecreatetruecolor($mediumWidth,$mediumHeight);
#small
$smallWidth = 327;
$smallHeight = 158;
$smallTmp = imagecreatetruecolor($smallWidth,$smallHeight);
but I wanted to enter the orignal into another folder as well, so I did the following thinking that getimagesize($_FILES['file']['tmp_name']) would return them correctly but it did not.
#original
$originalWidth = $width; //here and
$originalHeight = $height; // here
$originalTmp = imagecreatetruecolor($originalWidth,$originalHeight);
So how do I get the original image height and width as I have tried to do above?
$originalWidth and $originalHeight should return the specific images width & height, but it does not, that is the only issue I am having.
you want to check the size of
$_FILES['file']['tmp_name']
the actull uploaded file as stored on the system
not $_FILES['file']['name'] which is just the filename
What basically I am trying to do is to create a cover page for my personal website, just like facebook. Basically I am after the same layout of the cover as on facebook, so that user can get the same result while using the same cover on my site as well as on facebook.
The part I am stucked at is the "Drag image to position cover" thing.
The Facebook uses some algorithm to convert the cover image size to something different during dragging thing. For example, if the original image dimensions are 920x720, the dimensions of same image while it is on facebook setting-cover page(drag image to position cover thing), the dimensions of the image are 851x638.
I just wanted to know what algorithm facebook uses to set the image dimensions(from 720 to 638)
NOTE: The cover has to be the pixel perfect
I know that the cover dimension of facebook is 851x315, so here is what I am doing:
//$x = X origin cordinate variable obtained by dragging image
//$y = Y origin cordinate variable obtained by dragging image
list($k, $l) = getimagesize($src); // $src == image source
//$w = Needs to be calculated
//$h = Needs to be calculated
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( 854,316 );
imagecopyresampled($dst_r,$img_r,0,0,$x,$y,$w,$h,$k,$l);
imagejpeg($dst_r,$src,$jpeg_quality);
$img_name = writeToImage($src, $des); //writeToImage() is just a demo function created by me to do some other things with them which do not affect this part of code
echo $img_name;
I need to figure out how facebook calculates the new dimension of the image from previous one. Is it dependent of the actual(original) size of the image or is it dependent on some other factors?
The formulas for scaling images are quite simple.
$aspect_ratio = $original_width / $original_height;
$new_width = $new_height * $aspect_ratio;
or
$new_height = $new_width / $aspect_ratio;
I build a simple function with getimagesize to find out if an image is horizontal or vertical.
// get height and width and then return
list($width, $height) = getimagesize('/path/to/imag.jpg');
if ($width > $height || $width == $height) {
return 'HORIZONTAL';
} elseif ($height > $width) {
return 'VERTICAL';
}
But this seems to fail on some images. Especially on a picture that is taken with a mobile device, holding it vertical. Photoshop opens it and shows it vertical, Mac Preview does too, but getimagesize keeps telling me width is bigger than height.
So I assume the information, this "horizontal" image should be shown "vertical" in Photo application is stored somewhere else.....
But where.... Exif?
How can you tell the dimensions of a .jpeg or .png file without opening it?
If it is impossible to determine the dimensions, how can I automatically crop an image?
I am using PHP and JS.
list($width, $height) = getimagesize("img.jpg");
or
$im=imagecreatefromjpeg("image_testin_1.JPG");
imagetruecolortopalette($im, false, 255);
$w = imagesx($im);//provide width of full page
$h = imagesy($im);//provide height of full page