Page MenuHomePhabricator

ApiImageRotate.php

Authored By
bzimport
Nov 22 2014, 12:06 AM
Size
2 KB
Referenced Files
None
Subscribers
None

ApiImageRotate.php

<?php
/*
* Created on March 17th, 2012
* By Vivek Kumar Bagaria <vivekee047@gmail.com>
*/
class ApiImageRotate extends ApiBase {
protected $mParams ;
protected $mAngle = 0 ;
protected $mTitle ;
public function __construct( $main, $action ) {
parent::__construct( $main, $action );
}
public function execute() {
$this->initializeParams() ;
$user = $this->getUser() ;
//Spilting the title into various images
$imagelist = explode("|", $this->mTitle) ;
asort($imagelist) ;
// Looping over each image given in the title
foreach ($imagelist as $image) {
$FilePath = wfFindFile($image)->getLocalRefPath () ;
// Check if the rotation angle is a multiple of 90 degrees
if(!is_null($this->mAngle) && ($this->mAngle%90==0))
{
$this->mResultantImage = $this->rotateImage($FilePath) ;
$stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash() ;
$pathsaved = imagejpeg($this->mResultantImage,$FilePath) ;
}
}
}
public function rotateImage($FilePath){
$Imagesource = imagecreatefromjpeg($FilePath) ;
$rotatedImage = imagerotate($Imagesource, $this->mAngle,0) ;
return $rotatedImage ;
}
public function initializeParams()
{
$this->mParams = $this->extractRequestParams() ;
$this->mAngle = $this->mParams['angle'] ;
$this->mTitle = $this->mParams['title'] ;
}
public function getAllowedParams() {
return array(
'title' =>array(
ApiBase::PARAM_REQUIRED => true ,
),
'angle' => array(
ApiBase::PARAM_DFLT => 0,
),
);
}
public function getParamDescription() {
$p = $this->getModulePrefix() ;
return array(
'title' => 'The title of the image(s) to be rotated',
'angle' => 'The angle of rotation',
);
}
public function getVersion() {
return __CLASS__ . ': $Id: ApiParse.php 109693 2012-01-21 21:36:07Z $' ;
}
}

File Metadata

Mime Type
text/x-php
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
8217
Default Alt Text
ApiImageRotate.php (2 KB)

Event Timeline