2013-07-29 28 views
0

基本上我试图做的是为我的个人网站创建一个封面,就像Facebook一样。基本上,我的封面布局与Facebook上的布局相同,因此用户可以在我的网站以及脸书上使用相同的封面时获得相同的结果。如何调整像Facebook封面的图像大小

我被卡住的部分是“拖动图像定位封面”的东西。 Facebook使用一些算法来将封面图片尺寸转换为拖动东西时不同的东西。例如,如果原始图像尺寸是920x720,即在Facebook设置封面页面(将图像拖动到位置覆盖物)时的相同图像的尺寸,则图像的尺寸为851x638。

我只是想知道哪种算法Facebook的使用设置图像尺寸(从720到638)

注:封面必须是像素完美

我知道,盖尺寸脸谱是851x315,所以这里是我在做什么:

//$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; 

我需要弄清楚的Facebook如何计算从以前的一个图像的新维度。它取决于图像的实际(原始)大小还是取决于其他一些因素?

+0

你写了851x638。你的意思是815x638? – Herbert

+0

@赫伯特:不,我的意思是851x638。我很确定我在这种情况下写的像素。所以没有尺寸/像素错误 – ashutosh

+0

jquery拖动事件可能会帮助你。我通过弄乱Jcrop事件来克服这个问题。 [Jcrop概述](http://deepliquid.com/content/Jcrop.html) –

回答

0

缩放图像的公式非常简单。

$aspect_ratio = $original_width/$original_height; 

$new_width = $new_height * $aspect_ratio; 

$new_height = $new_width/$aspect_ratio;