how to compute Facebook graph api cover offset_y to pixel?

前端 未结 6 2048
故里飘歌
故里飘歌 2020-12-17 05:54

I can retrieve facebook cover source and offset_y from graph api for example -

https://graph.facebook.com/Inna

I get this -

\"cover\": {
           


        
6条回答
  •  粉色の甜心
    2020-12-17 06:47

    some solution on php i'm using PhpThumb_Factory:

            private $_cropX = 850;
            private $_cropY = 315;
            private $_origignalHeight;
            private $_origignalWidth;
    
     $scale = $this->caclScale($cover->cover->source);
            $thumb = \PhpThumb_Factory::create($imagePath);
    
                                $real_img_y = ($this->_cropX * $this->_origignalHeight / $this->_origignalWidth) - $this->_cropY;
    
                                $real_img_x = ($this->_cropY * $this->_origignalWidth / $this->_origignalHeight) - $this->_cropX;
    
                                $offset = $this->_authSession->offset;
    
    
                                $offset_x=($real_img_x * $offset['x'] / 100);
    
    
    
                                $offset_y=($real_img_y * $offset['y'] / 100);
    
                                $thumb->crop($offset_x, $offset_y, $this->_cropX, $this->_cropY);
    
                                $thumb->save($imagePath);
    
    
        private function caclScale($url) {
                $originalFileSizeParams = @exif_read_data($url);
        //            //$originalFileSize = $originalFileSizeParams['FileSize'];
        //            Zend_Debug::dump($originalFileSizeParams);
        //            die();
    
                $this->_origignalHeight = $originalFileSizeParams['COMPUTED']['Height'];
                $this->_origignalWidth = $originalFileSizeParams['COMPUTED']['Width'];
    
                if ($this->_origignalWidth < $this->_cropX) {
                    $scale = ($this->_cropX * 100) / $this->_origignalWidth;
                } else {
                    $scale = 100;
                }
                return $scale;
            }
    

提交回复
热议问题