本文整理汇总了PHP中OC_Image::preciseResize方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Image::preciseResize方法的具体用法?PHP OC_Image::preciseResize怎么用?PHP OC_Image::preciseResize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OC_Image
的用法示例。
在下文中一共展示了OC_Image::preciseResize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getThumbnail
public function getThumbnail($path)
{
$gallery_path = \OCP\Config::getSystemValue('datadirectory') . '/' . \OC_User::getUser() . '/gallery';
if (file_exists($gallery_path . $path)) {
return new \OC_Image($gallery_path . $path);
}
if (!\OC_Filesystem::file_exists($path)) {
\OC_Log::write(self::TAG, 'File ' . $path . ' don\'t exists', \OC_Log::WARN);
return false;
}
$image = new \OC_Image();
$image->loadFromFile(\OC_Filesystem::getLocalFile($path));
if (!$image->valid()) {
return false;
}
$image->fixOrientation();
$ret = $image->preciseResize(floor(150 * $image->width() / $image->height()), 150);
if (!$ret) {
\OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR);
unset($image);
return false;
}
$image->save($gallery_path . '/' . $path);
return $image;
}
示例2: mockGetPreview
/**
* @param $fileId
* @param $width
* @param $height
*
* @return object|\PHPUnit_Framework_MockObject_MockObject
*/
private function mockGetPreview($fileId, $width, $height)
{
$image = new \OC_Image(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg'));
$image->preciseResize($width, $height);
$preview = $this->getMockBuilder('\\OC\\Preview')->disableOriginalConstructor()->getMock();
$preview->method('getPreview')->willReturn($image);
$preview->method('isCached')->willReturn($fileId);
return $preview;
}
示例3: testPreciseResize
public function testPreciseResize()
{
$img = new \OC_Image(OC::$SERVERROOT . '/tests/data/testimage.png');
$this->assertTrue($img->preciseResize(128, 512));
$this->assertEquals(128, $img->width());
$this->assertEquals(512, $img->height());
$img = new \OC_Image(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.jpg'));
$this->assertTrue($img->preciseResize(64, 840));
$this->assertEquals(64, $img->width());
$this->assertEquals(840, $img->height());
$img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.gif')));
$this->assertTrue($img->preciseResize(1000, 1337));
$this->assertEquals(1000, $img->width());
$this->assertEquals(1337, $img->height());
}
示例4: getThumbnail
public function getThumbnail($path)
{
$gallery_storage = \OCP\Files::getStorage('gallery');
if ($gallery_storage->file_exists($path)) {
return new \OC_Image($gallery_storage->getLocalFile($path));
}
if (!\OC_Filesystem::file_exists($path)) {
\OC_Log::write(self::TAG, 'File ' . $path . ' don\'t exists', \OC_Log::WARN);
return false;
}
$image = new \OC_Image();
$image->loadFromFile(\OC_Filesystem::getLocalFile($path));
if (!$image->valid()) {
return false;
}
$image->fixOrientation();
$ret = $image->preciseResize(floor(self::THUMBNAIL_HEIGHT * $image->width() / $image->height()), self::THUMBNAIL_HEIGHT);
if (!$ret) {
\OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR);
unset($image);
return false;
}
$l = $gallery_storage->getLocalFile($path);
$image->save($l);
return $image;
}