public function calculateDimensions() { $db = Kwf_Registry::get('db'); $s = new Kwf_Model_Select(); $it = new Kwf_Model_Iterator_Packages(new Kwf_Model_Iterator_Rows(Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model'), $s)); foreach ($it as $row) { $this->_progressBar->next(1, 'calculating dimension ' . $row->id); if (file_exists($row->getFileSource())) { $size = @getimagesize($row->getFileSource()); if ($size) { $width = $size[0]; $height = $size[1]; $rotation = Kwf_Media_Image::getExifRotation($row->getFileSource()); $db->query("UPDATE `kwf_uploads` SET `is_image`=1, `image_width` = '{$width}', `image_height` = '{$height}', `image_rotation` = '{$rotation}' WHERE `id` = '{$row->id}';"); } } } }
public function testExifRotation() { $rotation = Kwf_Media_Image::getExifRotation('Kwf/Media/ImageExifRotation/rotation/rotation0.jpg'); $this->assertEquals($rotation, 0); $rotation = Kwf_Media_Image::getExifRotation('Kwf/Media/ImageExifRotation/rotation/rotation1.jpg'); $this->assertEquals($rotation, -90); $rotation = Kwf_Media_Image::getExifRotation('Kwf/Media/ImageExifRotation/rotation/rotation2.jpg'); $this->assertEquals($rotation, 180); $rotation = Kwf_Media_Image::getExifRotation('Kwf/Media/ImageExifRotation/rotation/rotation3.jpg'); $this->assertEquals($rotation, 90); $rotation = Kwf_Media_Image::getExifRotation('Kwf/Media/ImageExifRotation/rotation/rotationM0.JPG'); $this->assertEquals($rotation, 0); $rotation = Kwf_Media_Image::getExifRotation('Kwf/Media/ImageExifRotation/rotation/rotationM1.JPG'); $this->assertEquals($rotation, -90); $rotation = Kwf_Media_Image::getExifRotation('Kwf/Media/ImageExifRotation/rotation/rotationM2.JPG'); $this->assertEquals($rotation, 180); $rotation = Kwf_Media_Image::getExifRotation('Kwf/Media/ImageExifRotation/rotation/rotationM3.JPG'); $this->assertEquals($rotation, 90); }
private function _saveImageDimensions() { if (is_null($this->is_image)) { $size = null; if ($this->getFileSource() && is_file($this->getFileSource())) { $size = @getimagesize($this->getFileSource()); $rotation = Kwf_Media_Image::getExifRotation($this->getFileSource()); } if ($size) { $this->is_image = 1; $this->image_width = $size[0]; $this->image_height = $size[1]; $this->image_rotation = $rotation; } else { $this->is_image = 0; } $this->save(); } }
public function getFileInfo() { $ret = array('uploadId' => $this->id, 'mimeType' => $this->mime_type, 'filename' => $this->filename, 'extension' => $this->extension, 'fileSize' => $this->getFileSize(), 'hashKey' => $this->getHashKey()); if (!$this->id && is_file($this->filename)) { $ret['mimeType'] = $this->_getMimeType($this->filename); $ret['extension'] = substr(strrchr($this->filename, '.'), 1); } $size = @getimagesize($this->getFileSource()); if ($size) { $ret['image'] = true; if (abs(Kwf_Media_Image::getExifRotation($this->getFileSource())) == 90) { $size = array($size[1], $size[0]); } $ret['imageWidth'] = $size[0]; $ret['imageHeight'] = $size[1]; $ret['imageHandyScaleFactor'] = Kwf_Media_Image::getHandyScaleFactor($this->getFileSource()); } else { $ret['image'] = false; } return $ret; }