idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
50,700
|
public function get ( $ key , $ default = null ) { $ pieces = explode ( '.' , $ key ) ; $ config = $ this -> config ; foreach ( $ pieces as $ piece ) { if ( ! isset ( $ config [ $ piece ] ) ) { return $ default ; } $ config = $ config [ $ piece ] ; } return $ config ; }
|
Get the configuration value .
|
50,701
|
public function validate ( $ number , $ callback = null , $ account = null ) { if ( ! starts_with ( $ number , '2547' ) ) { throw new InvalidArgumentException ( 'The subscriber number must start with 2547' ) ; } $ time = Carbon :: now ( ) -> format ( 'YmdHis' ) ; $ configs = ( new ConfigurationRepository ) -> useAccount ( $ account ) ; $ shortCode = $ configs -> getAccountKey ( 'lnmo.shortcode' ) ; $ passkey = $ configs -> getAccountKey ( 'lnmo.passkey' ) ; $ callback = $ configs -> getAccountKey ( 'lnmo.callback' ) ; $ defaultCallback = $ configs -> getAccountKey ( 'id_validation_callback' ) ; $ initiator = $ configs -> getAccountKey ( 'initiator' ) ; $ body = [ 'Initiator' => $ initiator , 'BusinessShortCode' => $ shortCode , 'Password' => $ this -> getPassword ( $ shortCode , $ passkey , $ time ) , 'Timestamp' => $ time , 'TransactionType' => 'CheckIdentity' , 'PhoneNumber' => $ number , 'CallBackURL' => $ callback ? : $ defaultCallback , 'TransactionDesc' => ' ' ] ; try { $ response = $ this -> makeRequest ( $ body , Core :: instance ( ) -> getEndpoint ( MPESA_ID_CHECK , $ account ) , $ account ) ; return json_decode ( $ response -> getBody ( ) ) ; } catch ( RequestException $ exception ) { return json_decode ( $ exception -> getResponse ( ) -> getBody ( ) ) ; } }
|
Prepare the number validation request
|
50,702
|
private function makeRequest ( $ body , $ endpoint , $ account = null ) { return Core :: instance ( ) -> client ( ) -> request ( 'POST' , $ endpoint , [ 'headers' => [ 'Authorization' => 'Bearer ' . Core :: instance ( ) -> auth ( ) -> authenticate ( $ account ) , 'Content-Type' => 'application/json' , ] , 'json' => $ body , ] ) ; }
|
Initiate the request .
|
50,703
|
public function init ( ) { if ( $ this -> query === null ) { throw new InvalidConfigException ( get_class ( $ this ) . '::$query must be set.' ) ; } if ( $ this -> formatData === null ) { $ this -> formatData = function ( $ query , $ columns ) { $ rows = [ ] ; foreach ( $ query -> all ( ) as $ obj ) { $ row = [ ] ; foreach ( $ columns as $ column ) { if ( $ column [ 'data' ] ) { $ value = ArrayHelper :: getValue ( $ obj , $ column [ 'data' ] , null ) ; if ( ( $ pos = strrpos ( $ column [ 'data' ] , '.' ) ) !== false ) { $ keys = explode ( '.' , $ column [ 'data' ] ) ; $ a = $ value ; foreach ( array_reverse ( $ keys ) as $ key ) { $ a = [ $ key => $ a ] ; } $ row [ $ keys [ 0 ] ] = $ a [ $ keys [ 0 ] ] ; } else { $ row [ $ column [ 'data' ] ] = $ value ; } } } $ rows [ ] = $ row ; } return $ rows ; } ; } }
|
Check if query is configured
|
50,704
|
protected function getParam ( $ name , $ defaultValue = null ) { return $ this -> requestMethod == self :: REQUEST_METHOD_GET ? Yii :: $ app -> request -> getQueryParam ( $ name , $ defaultValue ) : Yii :: $ app -> request -> getBodyParam ( $ name , $ defaultValue ) ; }
|
Extract param from request
|
50,705
|
public function getAssetFilename ( $ file ) { $ settings = $ this -> parseAliases ( Plugin :: getInstance ( ) -> settings ) ; $ revver = new FilenameRev ( $ settings ) ; $ revver -> setBasePath ( CRAFT_BASE_PATH ) ; return $ revver -> rev ( $ file ) ; }
|
Get the filename of a asset .
|
50,706
|
protected function parseAliases ( Model $ settings ) { $ aliasables = [ 'manifestPath' , 'assetsBasePath' , 'assetUrlPrefix' ] ; foreach ( $ aliasables as $ aliasable ) { $ settings -> { $ aliasable } = Yii :: getAlias ( $ settings -> { $ aliasable } ) ; } return $ settings ; }
|
Replace Yii aliases .
|
50,707
|
public function getOptions ( ) { $ options = array ( ) ; if ( $ this -> valueSet ) { $ options [ 'value' ] = $ this -> getValue ( ) ; } elseif ( $ this -> hash !== null ) { $ options [ 'hash' ] = $ this -> getHash ( ) ; } $ options [ 'size' ] = $ this -> getSize ( ) ; $ options [ 'style' ] = $ this -> getStyle ( ) -> getOptions ( ) ; if ( $ this -> enableImageMagick !== null ) { $ options [ 'enableImageMagick' ] = $ this -> getEnableImageMagick ( ) ; } if ( $ this -> iconGenerator !== IconGenerator :: getDefaultGenerator ( ) ) { $ options [ 'iconGenerator' ] = $ this -> getIconGenerator ( ) ; } return $ options ; }
|
Gets an associative array of all options of this identicon .
|
50,708
|
public function setSize ( $ size ) { if ( ! is_numeric ( $ size ) || $ size < 1 ) { throw new \ InvalidArgumentException ( "An invalid identicon size was specified. " . "A numeric value >= 1 was expected. Specified value: $size." ) ; } $ this -> size = ( int ) $ size ; }
|
Sets the size of this icon in pixels .
|
50,709
|
public function setEnableImageMagick ( $ enable ) { if ( ! is_bool ( $ enable ) ) { throw new \ InvalidArgumentException ( "enableImageMagick can only assume boolean values. Specified value: $enable." ) ; } if ( $ enable && ! extension_loaded ( 'imagick' ) ) { throw new \ Exception ( 'Failed to enable ImageMagick. ' . 'The Imagick PHP extension was not found on this system.' ) ; } $ this -> enableImageMagick = $ enable ; }
|
Sets whether ImageMagick should be used to generate PNG icons .
|
50,710
|
public function setStyle ( $ style ) { if ( $ style == null ) { $ this -> style = new IdenticonStyle ( ) ; } elseif ( $ style instanceof IdenticonStyle ) { $ this -> style = $ style ; } elseif ( is_array ( $ style ) ) { $ this -> style = new IdenticonStyle ( $ style ) ; } else { throw new \ InvalidArgumentException ( "Invalid indenticon style was specified. " . "Allowed values are IdenticonStyle instances and associative " . "arrays containing IdenticonStyle options." ) ; } return $ this ; }
|
Gets or sets the style of the icon .
|
50,711
|
public function setHash ( $ hash ) { if ( ! is_string ( $ hash ) ) { throw new \ InvalidArgumentException ( 'An invalid $hash was passed to Identicon. ' . 'A binary string was expected.' ) ; } if ( strlen ( $ hash ) < 6 ) { throw new \ InvalidArgumentException ( 'An invalid $hash was passed to Identicon. ' . 'The hash was expected to contain at least 6 bytes.' ) ; } $ this -> hash = $ hash ; $ this -> value = null ; $ this -> valueSet = false ; return $ this ; }
|
Sets a binary string containing the hash that is used as base for this icon . The string should contain at least 6 bytes .
|
50,712
|
public function setValue ( $ value ) { $ this -> hash = sha1 ( "$value" ) ; $ this -> value = $ value ; $ this -> valueSet = true ; return $ this ; }
|
Sets a value that will be used as base for this icon . The value will be converted to a string and then hashed using SHA1 .
|
50,713
|
public function getIconBounds ( ) { $ padding = ( int ) ( $ this -> style -> getPadding ( ) * $ this -> size + 0.5 ) ; return new Rectangle ( $ padding , $ padding , $ this -> size - $ padding * 2 , $ this -> size - $ padding * 2 ) ; }
|
Gets the bounds of the icon excluding its padding .
|
50,714
|
public function draw ( \ Jdenticon \ Rendering \ RendererInterface $ renderer , \ Jdenticon \ Rendering \ Rectangle $ rect = null ) { if ( $ rect === null ) { $ rect = $ this -> getIconBounds ( ) ; } $ this -> iconGenerator -> generate ( $ renderer , $ rect , $ this -> style , $ this -> hash ) ; }
|
Draws this icon using a specified renderer .
|
50,715
|
public function displayImage ( $ imageFormat = 'png' ) { $ renderer = $ this -> getRenderer ( $ imageFormat ) ; $ this -> draw ( $ renderer , $ this -> getIconBounds ( ) ) ; $ mimeType = $ renderer -> getMimeType ( ) ; $ data = $ renderer -> getData ( ) ; header ( "Content-Type: $mimeType" ) ; echo $ data ; }
|
Renders the icon directly to the page output .
|
50,716
|
public function getImageData ( $ imageFormat = 'png' ) { $ renderer = $ this -> getRenderer ( $ imageFormat ) ; $ this -> draw ( $ renderer , $ this -> getIconBounds ( ) ) ; return $ renderer -> getData ( ) ; }
|
Renders the icon to a binary string .
|
50,717
|
public function getImageDataUri ( $ imageFormat = 'png' ) { $ renderer = $ this -> getRenderer ( $ imageFormat ) ; $ this -> draw ( $ renderer , $ this -> getIconBounds ( ) ) ; $ mimeType = $ renderer -> getMimeType ( ) ; $ base64 = base64_encode ( $ renderer -> getData ( ) ) ; return "data:$mimeType;base64,$base64" ; }
|
Renders the icon as a data URI . It is recommended to avoid using this method unless really necessary since it will effectively disable client caching of generated icons and will also cause the same icon to be rendered multiple times when used multiple times on a single page .
|
50,718
|
private static function getIntersections ( $ edges , $ y ) { $ intersections = array ( ) ; foreach ( $ edges as $ edge ) { if ( $ edge -> y0 < $ y && $ edge -> y1 >= $ y || $ edge -> y0 >= $ y && $ edge -> y1 < $ y ) { $ x = $ edge -> x0 + ( $ edge -> x1 - $ edge -> x0 ) * ( $ y - $ edge -> y0 ) / ( $ edge -> y1 - $ edge -> y0 ) ; $ intersections [ ] = new EdgeSuperSampleIntersection ( $ x , $ edge ) ; } } usort ( $ intersections , array ( 'Jdenticon\\Canvas\\Rasterization\\Rasterizer' , 'intersection_cmp' ) ) ; return $ intersections ; }
|
Determines what edges that intersect a horizontal line with the specified y coordinate . For each intersecting edge the intersecting x coordinate is returned .
|
50,719
|
private static function getSuperSampleRanges ( & $ scanline , $ width ) { $ superSampleRanges = array ( ) ; $ rangeIndex = 0 ; $ scanlineCount = count ( $ scanline ) ; while ( $ rangeIndex < $ scanlineCount ) { $ range = $ scanline [ $ rangeIndex ] ; if ( $ range -> fromX >= $ width ) { break ; } $ superSampleRange = new SuperSampleRange ( $ range -> fromX , $ range -> fromX + $ range -> width ) ; $ superSampleRange -> edges [ ] = $ range -> edge ; $ rangeIndex ++ ; for ( $ i = $ rangeIndex ; $ i < $ scanlineCount ; $ i ++ ) { $ range = $ scanline [ $ i ] ; if ( $ range -> fromX < $ superSampleRange -> toXExcl ) { $ superSampleRange -> toXExcl = max ( $ superSampleRange -> toXExcl , $ range -> fromX + $ range -> width ) ; $ superSampleRange -> edges [ ] = $ range -> edge ; $ rangeIndex ++ ; } else { break ; } } $ superSampleRange -> toXExcl = min ( $ superSampleRange -> toXExcl , $ width ) ; $ superSampleRange -> width = $ superSampleRange -> toXExcl - $ superSampleRange -> fromX ; $ superSampleRanges [ ] = $ superSampleRange ; } return $ superSampleRanges ; }
|
Determines what ranges of a scanline that needs to be supersampled .
|
50,720
|
public static function getOuterShapes ( ) { if ( self :: $ outerShapes === null ) { self :: $ outerShapes = self :: createOuterShapes ( ) ; } return self :: $ outerShapes ; }
|
Gets an array of all possible outer shapes . Do not modify the returned array .
|
50,721
|
public static function getCenterShapes ( ) { if ( self :: $ centerShapes === null ) { self :: $ centerShapes = self :: createCenterShapes ( ) ; } return self :: $ centerShapes ; }
|
Gets an array of all possible center shapes . Do not modify the returned array .
|
50,722
|
public function getData ( $ fragment = false ) { $ svg = '' ; $ widthAsString = number_format ( $ this -> width , 0 , '.' , '' ) ; $ heightAsString = number_format ( $ this -> height , 0 , '.' , '' ) ; if ( ! $ fragment ) { $ svg .= '<svg xmlns="http://www.w3.org/2000/svg" width="' . $ widthAsString . '" height="' . $ heightAsString . '" viewBox="0 0 ' . $ widthAsString . ' ' . $ heightAsString . '" preserveAspectRatio="xMidYMid meet">' ; } if ( $ this -> backgroundColor -> a > 0 ) { $ opacity = ( float ) $ this -> backgroundColor -> a / 255 ; $ svg .= '<rect fill="' . $ this -> backgroundColor -> toHexString ( 6 ) . '" fill-opacity="' . number_format ( $ opacity , 2 , '.' , '' ) . '" x="0" y="0" width="' . $ widthAsString . '" height="' . $ heightAsString . '"/>' ; } foreach ( $ this -> pathsByColor as $ color => $ path ) { $ svg .= "<path fill=\"$color\" d=\"$path\"/>" ; } if ( ! $ fragment ) { $ svg .= '</svg>' ; } return $ svg ; }
|
Generates an SVG string of the renderer output .
|
50,723
|
public function emptyTo ( & $ colorData , $ count ) { for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ sampleCount = $ this -> samples [ $ i * 5 + self :: IDX_COUNT ] ; $ a = $ this -> samples [ $ i * 5 + self :: IDX_A ] ; $ color = $ sampleCount == 0 || $ a == 0 ? 0 : ColorUtils :: from ( ( int ) ( $ a / $ sampleCount ) , ( int ) ( $ this -> samples [ $ i * 5 + self :: IDX_R ] / $ a ) , ( int ) ( $ this -> samples [ $ i * 5 + self :: IDX_G ] / $ a ) , ( int ) ( $ this -> samples [ $ i * 5 + self :: IDX_B ] / $ a ) ) ; $ colorData [ ] = 1 ; $ colorData [ ] = $ color ; } $ this -> pixelOffset = 0 ; $ this -> subPixelOffset = 0 ; $ this -> used = - 1 ; }
|
Writes the average color of each pixel to a specified color array .
|
50,724
|
public function colorAt ( $ index ) { $ sampleCount = $ this -> samples [ $ index * 5 + self :: IDX_COUNT ] ; $ alphaSum = $ this -> samples [ $ index * 5 + self :: IDX_A ] ; return $ sampleCount == 0 || $ alphaSum == 0 ? 0 : ColorUtils :: from ( ( int ) ( $ alphaSum / $ sampleCount ) , ( int ) ( $ this -> samples [ $ index * 5 + self :: IDX_R ] / $ alphaSum ) , ( int ) ( $ this -> samples [ $ index * 5 + self :: IDX_G ] / $ alphaSum ) , ( int ) ( $ this -> samples [ $ index * 5 + self :: IDX_B ] / $ alphaSum ) ) ; }
|
Gets the average color of the pixel at a specified index .
|
50,725
|
private function _add ( $ count , $ a , $ r , $ g , $ b ) { if ( $ this -> used < $ this -> pixelOffset ) { $ this -> used = $ this -> pixelOffset ; $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_COUNT ] = $ count ; $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_A ] = $ a * $ count ; $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_R ] = $ a * $ r * $ count ; $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_G ] = $ a * $ g * $ count ; $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_B ] = $ a * $ b * $ count ; } else { $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_COUNT ] += $ count ; if ( $ a > 0 ) { $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_A ] += $ a * $ count ; $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_R ] += $ a * $ r * $ count ; $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_G ] += $ a * $ g * $ count ; $ this -> samples [ $ this -> pixelOffset * 5 + self :: IDX_B ] += $ a * $ b * $ count ; } } }
|
Adds a color to the current pixel in the buffer .
|
50,726
|
public function add ( $ color , $ untilX ) { $ samplesLeft = ( int ) ( $ untilX * $ this -> samplesPerPixel ) - $ this -> subPixelOffset - $ this -> pixelOffset * $ this -> samplesPerPixel ; $ a = ( $ color ) & 0xff ; $ r = ( $ color >> 24 ) & 0xff ; $ g = ( $ color >> 16 ) & 0xff ; $ b = ( $ color >> 8 ) & 0xff ; if ( $ this -> subPixelOffset > 0 ) { $ samples = $ this -> samplesPerPixel - $ this -> subPixelOffset ; if ( $ samples > $ samplesLeft ) { $ samples = $ samplesLeft ; } $ samplesLeft -= $ samples ; $ this -> _add ( $ samples , $ a , $ r , $ g , $ b ) ; $ this -> subPixelOffset += $ samples ; if ( $ this -> subPixelOffset == $ this -> samplesPerPixel ) { $ this -> subPixelOffset = 0 ; $ this -> pixelOffset ++ ; } } $ fullPixels = ( int ) ( $ samplesLeft / $ this -> samplesPerPixel ) ; if ( $ fullPixels > 0 ) { for ( $ i = 0 ; $ i < $ fullPixels ; $ i ++ ) { $ this -> _add ( $ this -> samplesPerPixel , $ a , $ r , $ g , $ b ) ; $ this -> pixelOffset ++ ; } $ samplesLeft -= $ fullPixels * $ this -> samplesPerPixel ; } if ( $ samplesLeft > 0 ) { $ this -> _add ( $ samplesLeft , $ a , $ r , $ g , $ b ) ; $ this -> subPixelOffset += $ samplesLeft ; if ( $ this -> subPixelOffset == $ this -> samplesPerPixel ) { $ this -> subPixelOffset = 0 ; $ this -> pixelOffset ++ ; } } }
|
Adds a color to the buffer up until the specified x index .
|
50,727
|
public function copyTo ( LayerManager $ other ) { $ other -> color = $ this -> color ; $ layer = $ this -> topLayer ; $ previousCopy = null ; while ( $ layer !== null ) { $ copy = new Layer ( $ layer -> polygonId , $ layer -> color , $ layer -> winding , $ layer -> windingRule ) ; if ( $ previousCopy === null ) { $ other -> topLayer = $ copy ; } else { $ previousCopy -> nextLayer = $ copy ; } $ previousCopy = $ copy ; $ layer = $ layer -> nextLayer ; } }
|
Copies all layers in this manager to another LayerManager .
|
50,728
|
public function add ( Edge $ edge ) { $ dwinding = $ edge -> y0 < $ edge -> y1 ? 1 : - 1 ; $ layer = $ this -> topLayer ; $ previousLayer = null ; while ( $ layer !== null ) { if ( $ layer -> polygonId === $ edge -> polygonId ) { $ layer -> winding += $ dwinding ; $ inPath = $ layer -> windingRule == 'evenodd' ? ( $ layer -> winding % 2 === 1 ) : ( $ layer -> winding !== 0 ) ; if ( ! $ inPath ) { if ( $ previousLayer === null ) { $ this -> topLayer = $ layer -> nextLayer ; } else { $ previousLayer -> nextLayer = $ layer -> nextLayer ; } } break ; } elseif ( $ layer -> polygonId < $ edge -> polygonId ) { $ newLayer = new Layer ( $ edge -> polygonId , $ edge -> color , $ dwinding , $ edge -> windingRule ) ; $ newLayer -> nextLayer = $ layer ; if ( $ previousLayer === null ) { $ this -> topLayer = $ newLayer ; } else { $ previousLayer -> nextLayer = $ newLayer ; } break ; } $ previousLayer = $ layer ; $ layer = $ layer -> nextLayer ; } if ( $ layer === null ) { $ newLayer = new Layer ( $ edge -> polygonId , $ edge -> color , $ dwinding , $ edge -> windingRule ) ; if ( $ previousLayer === null ) { $ this -> topLayer = $ newLayer ; } else { $ previousLayer -> nextLayer = $ newLayer ; } } $ color = ColorUtils :: TRANSPARENT ; $ layer = $ this -> topLayer ; while ( $ layer !== null && ( $ color & 0xff ) < 255 ) { if ( $ layer -> color === ColorUtils :: FORCE_TRANSPARENT ) { break ; } $ color = ColorUtils :: over ( $ layer -> color , $ color ) ; } $ this -> color = $ color ; }
|
Adds a layer for the specified edge . The z - order is defined by its id .
|
50,729
|
public function setBackgroundColor ( \ Jdenticon \ Color $ color ) { parent :: setBackgroundColor ( $ color ) ; $ this -> canvas -> backColor = $ this -> backgroundColor -> toRgba ( ) ; }
|
Sets the background color of the icon .
|
50,730
|
public function writeImageHeader ( $ width , $ height , $ colorType ) { $ this -> buffer -> startChunk ( "IHDR" ) ; $ this -> buffer -> writeUInt32BE ( $ width ) ; $ this -> buffer -> writeUInt32BE ( $ height ) ; $ this -> buffer -> writeUInt8 ( 8 ) ; $ this -> buffer -> writeUInt8 ( $ colorType ) ; $ this -> buffer -> writeUInt8 ( 0 ) ; $ this -> buffer -> writeUInt8 ( 0 ) ; $ this -> buffer -> writeUInt8 ( 0 ) ; $ this -> buffer -> endChunk ( ) ; }
|
Writes an IHDR chunk to the png data stream .
|
50,731
|
public function writeImageGamma ( $ gamma = 45455 ) { $ this -> buffer -> startChunk ( "gAMA" ) ; $ this -> buffer -> writeUInt32BE ( $ gamma ) ; $ this -> buffer -> endChunk ( ) ; }
|
Writes a gAMA chunk to the png data stream .
|
50,732
|
public function writeTrueColorWithAlpha ( array & $ colorRanges , $ width , $ height ) { $ this -> buffer -> startChunk ( "IDAT" ) ; $ uncompressed = '' ; $ count = - 1 ; $ x = 0 ; foreach ( $ colorRanges as $ value ) { if ( $ count === - 1 ) { $ count = $ value ; } else { if ( $ count !== 0 ) { if ( $ x === $ width ) { $ x = 0 ; } if ( $ x === 0 ) { $ uncompressed .= pack ( 'C' , 0 ) ; } $ uncompressed .= str_repeat ( pack ( 'N' , $ value ) , $ count ) ; $ x += $ count ; } $ count = - 1 ; } } $ compressed = gzcompress ( $ uncompressed , 2 ) ; $ this -> buffer -> writeString ( $ compressed ) ; $ this -> buffer -> endChunk ( ) ; }
|
Writes an IDAT chunk of truecolor encoded image data .
|
50,733
|
public function writeIndexed ( array & $ colorRanges , PngPalette $ palette , $ width , $ height ) { $ this -> buffer -> startChunk ( "IDAT" ) ; $ uncompressed = '' ; $ count = - 1 ; $ x = 0 ; foreach ( $ colorRanges as $ value ) { if ( $ count === - 1 ) { $ count = $ value ; } else { if ( $ count !== 0 ) { if ( $ x === $ width ) { $ x = 0 ; } if ( $ x === 0 ) { $ uncompressed .= pack ( 'C' , 0 ) ; } $ colorIndex = $ palette -> lookup [ $ value ] ; $ uncompressed .= str_repeat ( pack ( 'C' , $ colorIndex ) , $ count ) ; $ x += $ count ; } $ count = - 1 ; } } $ compressed = gzcompress ( $ uncompressed , 2 ) ; $ this -> buffer -> writeString ( $ compressed ) ; $ this -> buffer -> endChunk ( ) ; }
|
Writes an IDAT chunk of indexed image data .
|
50,734
|
public function writePalette ( PngPalette $ palette ) { if ( $ palette && $ palette -> isValid ) { $ this -> buffer -> startChunk ( "PLTE" ) ; foreach ( $ palette -> colors as $ color ) { $ this -> buffer -> writeString ( pack ( 'C' , ( $ color >> 24 ) & 0xff ) . pack ( 'C' , ( $ color >> 16 ) & 0xff ) . pack ( 'C' , ( $ color >> 8 ) & 0xff ) ) ; } $ this -> buffer -> endChunk ( ) ; } }
|
Writes a PLTE chunk containing the indexed colors .
|
50,735
|
public function writeTransparency ( PngPalette $ palette ) { if ( $ palette && $ palette -> isValid && $ palette -> hasAlphaChannel ) { $ this -> buffer -> startChunk ( "tRNS" ) ; $ alpha = '' ; foreach ( $ palette -> colors as $ color ) { $ alpha .= pack ( 'C' , $ color & 0xff ) ; } $ this -> buffer -> writeString ( $ alpha ) ; $ this -> buffer -> endChunk ( ) ; } }
|
Writes a tRNS chunk containing the alpha values of indexed colors .
|
50,736
|
public function writeTextualData ( $ key , $ value ) { $ this -> buffer -> startChunk ( "tEXt" ) ; $ this -> buffer -> writeString ( $ key ) ; $ this -> buffer -> writeUInt8 ( 0 ) ; $ this -> buffer -> writeString ( $ value ) ; $ this -> buffer -> endChunk ( ) ; }
|
Writes a tEXt chunk containing the specified strings .
|
50,737
|
public function addCircle ( $ x , $ y , $ size , $ counterClockwise ) { $ sweepFlag = $ counterClockwise ? '0' : '1' ; $ radiusAsString = number_format ( $ size / 2 , 2 , '.' , '' ) ; $ this -> dataString .= 'M' . number_format ( $ x , 2 , '.' , '' ) . ' ' . number_format ( $ y + $ size / 2 , 2 , '.' , '' ) . 'a' . $ radiusAsString . ',' . $ radiusAsString . ' 0 1,' . $ sweepFlag . ' ' . number_format ( $ size , 2 , '.' , '' ) . ',0' . 'a' . $ radiusAsString . ',' . $ radiusAsString . ' 0 1,' . $ sweepFlag . ' ' . number_format ( - $ size , 2 , '.' , '' ) . ',0' ; }
|
Adds a circle to the SVG .
|
50,738
|
public function addPolygon ( $ points ) { $ pointCount = count ( $ points ) ; $ this -> dataString .= 'M' . number_format ( $ points [ 0 ] -> x , 2 , '.' , '' ) . ' ' . number_format ( $ points [ 0 ] -> y , 2 , '.' , '' ) ; for ( $ i = 1 ; $ i < $ pointCount ; $ i ++ ) { $ this -> dataString .= 'L' . number_format ( $ points [ $ i ] -> x , 2 , '.' , '' ) . ' ' . number_format ( $ points [ $ i ] -> y , 2 , '.' , '' ) ; } $ this -> dataString .= 'Z' ; }
|
Adds a polygon to the SVG .
|
50,739
|
public static function fromVector ( $ x0 , $ y0 , $ x1 , $ y1 ) { $ line = new ImagickRendererLine ( ) ; $ line -> Px = $ x0 ; $ line -> Py = $ y0 ; $ line -> rx = $ x1 - $ x0 ; $ line -> ry = $ y1 - $ y0 ; return $ line ; }
|
Creates a new line from a vector .
|
50,740
|
public function moveRight ( $ distance ) { $ rx = - $ this -> ry ; $ ry = $ this -> rx ; $ multiplier = $ distance / sqrt ( $ rx * $ rx + $ ry * $ ry ) ; $ this -> Px += $ rx * $ multiplier ; $ this -> Py += $ ry * $ multiplier ; }
|
Moves the line to the right relative the direction vector .
|
50,741
|
public static function intersection ( ImagickRendererLine $ l1 , ImagickRendererLine $ l2 ) { $ rs = $ l1 -> rx * $ l2 -> ry - $ l1 -> ry * $ l2 -> rx ; if ( $ rs == 0 ) { return null ; } $ u = ( ( $ l2 -> Px - $ l1 -> Px ) * $ l1 -> ry - ( $ l2 -> Py - $ l1 -> Py ) * $ l1 -> rx ) / $ rs ; return new Point ( $ l2 -> Px + $ u * $ l2 -> rx , $ l2 -> Py + $ u * $ l2 -> ry ) ; }
|
Computes the point at which two lines intersect .
|
50,742
|
public function getData ( ) { $ imagick = new \ Imagick ( ) ; $ imagick -> newImage ( $ this -> width , $ this -> height , $ this -> backgroundColor -> __toString ( ) ) ; $ imagick -> setImageFormat ( 'png' ) ; if ( method_exists ( $ imagick , 'setImageProperty' ) ) { $ imagick -> setImageProperty ( 'Software' , 'Jdenticon' ) ; } else { $ imagick -> setImageAttribute ( 'Software' , 'Jdenticon' ) ; } $ imagick -> drawImage ( $ this -> draw ) ; return $ imagick -> getImageBlob ( ) ; }
|
Renders this image as a PNG data stream .
|
50,743
|
protected function getShapes ( $ colorTheme , $ hash ) { $ usedColorThemeIndexes = array ( ) ; $ categories = self :: getCategories ( ) ; $ shapes = array ( ) ; $ colorCount = $ colorTheme -> getCount ( ) ; foreach ( $ categories as $ category ) { $ colorThemeIndex = self :: getOctet ( $ hash , $ category -> colorIndex ) % $ colorCount ; if ( self :: isDuplicate ( $ usedColorThemeIndexes , $ colorThemeIndex , array ( 0 , 4 ) ) || self :: isDuplicate ( $ usedColorThemeIndexes , $ colorThemeIndex , array ( 2 , 3 ) ) ) { $ colorThemeIndex = 1 ; } $ usedColorThemeIndexes [ ] = $ colorThemeIndex ; $ startRotationIndex = $ category -> rotationIndex === null ? 0 : self :: getOctet ( $ hash , $ category -> rotationIndex ) ; $ shapeIndex = self :: getOctet ( $ hash , $ category -> shapeIndex ) % count ( $ category -> shapes ) ; $ shape = $ category -> shapes [ $ shapeIndex ] ; $ shapes [ ] = new Shape ( $ shape , $ colorTheme -> getByIndex ( $ colorThemeIndex ) , $ category -> positions , $ startRotationIndex ) ; } return $ shapes ; }
|
Gets an enumeration of individual shapes to be rendered in an icon for a specific hash .
|
50,744
|
protected function renderBackground ( \ Jdenticon \ Rendering \ RendererInterface $ renderer , \ Jdenticon \ Rendering \ Rectangle $ rect , \ Jdenticon \ IdenticonStyle $ style , \ Jdenticon \ Rendering \ ColorTheme $ colorTheme , $ hash ) { $ renderer -> setBackgroundColor ( $ style -> getBackgroundColor ( ) ) ; }
|
Renders the background of an icon .
|
50,745
|
protected function renderForeground ( \ Jdenticon \ Rendering \ RendererInterface $ renderer , \ Jdenticon \ Rendering \ Rectangle $ rect , \ Jdenticon \ IdenticonStyle $ style , \ Jdenticon \ Rendering \ ColorTheme $ colorTheme , $ hash ) { $ normalizedRect = $ this -> normalizeRectangle ( $ rect ) ; $ cellSize = $ normalizedRect -> width / $ this -> getCellCount ( ) ; foreach ( $ this -> getShapes ( $ colorTheme , $ hash ) as $ shape ) { $ rotation = $ shape -> startRotationIndex ; $ renderer -> beginShape ( $ shape -> color ) ; $ positionCount = count ( $ shape -> positions ) ; for ( $ i = 0 ; $ i + 1 < $ positionCount ; $ i += 2 ) { $ renderer -> setTransform ( new Transform ( $ normalizedRect -> x + $ shape -> positions [ $ i + 0 ] * $ cellSize , $ normalizedRect -> y + $ shape -> positions [ $ i + 1 ] * $ cellSize , $ cellSize , $ rotation ++ % 4 ) ) ; $ shape -> definition -> __invoke ( $ renderer , $ cellSize , $ i / 2 ) ; } $ renderer -> endShape ( ) ; } }
|
Renders the foreground of an icon .
|
50,746
|
public function generate ( \ Jdenticon \ Rendering \ RendererInterface $ renderer , \ Jdenticon \ Rendering \ Rectangle $ rect , \ Jdenticon \ IdenticonStyle $ style , $ hash ) { $ hue = self :: getHue ( $ hash ) ; $ colorTheme = new ColorTheme ( $ hue , $ style ) ; $ this -> renderBackground ( $ renderer , $ rect , $ style , $ colorTheme , $ hash ) ; $ this -> renderForeground ( $ renderer , $ rect , $ style , $ colorTheme , $ hash ) ; }
|
Generates an identicon for the specified hash .
|
50,747
|
public function getByIndex ( $ index ) { if ( $ index === 0 ) return $ this -> darkGray ; if ( $ index === 1 ) return $ this -> midColor ; if ( $ index === 2 ) return $ this -> lightGray ; if ( $ index === 3 ) return $ this -> lightColor ; if ( $ index === 4 ) return $ this -> darkColor ; return null ; }
|
Gets a color from this color theme by index .
|
50,748
|
public function toPng ( $ keywords = array ( ) ) { $ colorRanges = array ( ) ; Rasterizer :: rasterize ( $ colorRanges , $ this -> edges , $ this -> width , $ this -> height ) ; $ backColor = ColorUtils :: parse ( $ this -> backColor ) ; if ( ColorUtils :: alpha ( $ backColor ) > 0 ) { $ isColor = false ; foreach ( $ colorRanges as & $ value ) { if ( $ isColor ) { $ value = ColorUtils :: over ( $ value , $ backColor ) ; $ isColor = false ; } else { $ isColor = true ; } } unset ( $ value ) ; } $ palette = new PngPalette ( $ colorRanges ) ; $ png = new PngEncoder ( ) ; $ png -> writeImageHeader ( $ this -> width , $ this -> height , $ palette -> isValid ? PngEncoder :: INDEXED_COLOR : PngEncoder :: TRUE_COLOR_WITH_ALPHA ) ; $ png -> writeImageGamma ( ) ; foreach ( $ keywords as $ key => $ value ) { $ png -> writeTextualData ( $ key , $ value ) ; } if ( $ palette && $ palette -> isValid ) { $ png -> writePalette ( $ palette ) ; $ png -> writeTransparency ( $ palette ) ; $ png -> writeIndexed ( $ colorRanges , $ palette , $ this -> width , $ this -> height ) ; } else { $ png -> writeTrueColorWithAlpha ( $ colorRanges , $ this -> width , $ this -> height ) ; } $ png -> writeImageEnd ( ) ; return $ png -> getBuffer ( ) ; }
|
Renders the canvas as a PNG data stream .
|
50,749
|
public static function fromRgb ( $ red , $ green , $ blue , $ alpha = 255 ) { $ color = new Color ( ) ; $ color -> r = $ red ; $ color -> g = $ green ; $ color -> b = $ blue ; $ color -> a = $ alpha ; return $ color ; }
|
Creates a Color from an RGB value .
|
50,750
|
public static function fromHsl ( $ hue , $ saturation , $ lightness , $ alpha = 1.0 ) { if ( $ hue < 0 ) $ hue = 0 ; if ( $ hue > 1 ) $ hue = 1 ; if ( $ saturation < 0 ) $ saturation = 0 ; if ( $ saturation > 1 ) $ saturation = 1 ; if ( $ lightness < 0 ) $ lightness = 0 ; if ( $ lightness > 1 ) $ lightness = 1 ; if ( $ alpha < 0 ) $ alpha = 0 ; if ( $ alpha > 1 ) $ alpha = 1 ; if ( $ saturation == 0 ) { $ value = ( int ) ( $ lightness * 255 ) ; return self :: fromRgb ( $ value , $ value , $ value , ( int ) ( $ alpha * 255 ) ) ; } else { if ( $ lightness <= 0.5 ) { $ m2 = $ lightness * ( $ saturation + 1 ) ; } else { $ m2 = $ lightness + $ saturation - $ lightness * $ saturation ; } $ m1 = $ lightness * 2 - $ m2 ; return self :: fromRgb ( self :: hueToRgb ( $ m1 , $ m2 , $ hue * 6 + 2 ) , self :: hueToRgb ( $ m1 , $ m2 , $ hue * 6 ) , self :: hueToRgb ( $ m1 , $ m2 , $ hue * 6 - 2 ) , ( int ) ( $ alpha * 255 ) ) ; } }
|
Creates a Color instance from HSL color parameters .
|
50,751
|
public static function fromHslCompensated ( $ hue , $ saturation , $ lightness , $ alpha = 1.0 ) { if ( $ hue < 0 ) $ hue = 0 ; if ( $ hue > 1 ) $ hue = 1 ; $ lightnessCompensation = self :: $ lightnessCompensations [ ( int ) ( $ hue * 6 + 0.5 ) ] ; $ lightness = $ lightness < 0.5 ? $ lightness * $ lightnessCompensation * 2 : $ lightnessCompensation + ( $ lightness - 0.5 ) * ( 1 - $ lightnessCompensation ) * 2 ; return self :: fromHsl ( $ hue , $ saturation , $ lightness , $ alpha ) ; }
|
Creates a Color > instance from HSL color parameters and will compensate the lightness for hues that appear to be darker than others .
|
50,752
|
private static function hueToRgb ( $ m1 , $ m2 , $ h ) { if ( $ h < 0 ) { $ h = $ h + 6 ; } elseif ( $ h > 6 ) { $ h = $ h - 6 ; } if ( $ h < 1 ) { $ r = $ m1 + ( $ m2 - $ m1 ) * $ h ; } elseif ( $ h < 3 ) { $ r = $ m2 ; } elseif ( $ h < 4 ) { $ r = $ m1 + ( $ m2 - $ m1 ) * ( 4 - $ h ) ; } else { $ r = $ m1 ; } return ( int ) ( 255 * $ r ) ; }
|
Helper method for FromHsl
|
50,753
|
public static function parse ( $ value ) { if ( $ value instanceof Color ) { return $ value ; } $ value = strtolower ( "$value" ) ; if ( preg_match ( '/^#?[0-9a-f]{3,8}$/' , $ value ) && self :: parseHexColor ( $ value , $ result ) ) { return $ result ; } if ( preg_match ( '/^rgba?\\(([^,]+),([^,]+),([^,]+)(?:,([^,]+))?\\)$/' , $ value , $ matches ) && self :: parseRgbComponent ( $ matches [ 1 ] , $ r ) && self :: parseRgbComponent ( $ matches [ 2 ] , $ g ) && self :: parseRgbComponent ( $ matches [ 3 ] , $ b ) && self :: parseAlpha ( isset ( $ matches [ 4 ] ) ? $ matches [ 4 ] : null , $ a ) ) { return self :: fromRgb ( $ r , $ g , $ b , ( int ) ( 255 * $ a ) ) ; } if ( preg_match ( '/^hsla?\\(([^,]+),([^,]+),([^,]+)(?:,([^,]+))?\\)$/' , $ value , $ matches ) && self :: parseHue ( $ matches [ 1 ] , $ h ) && self :: parsePercent ( $ matches [ 2 ] , $ s ) && self :: parsePercent ( $ matches [ 3 ] , $ l ) && self :: parseAlpha ( isset ( $ matches [ 4 ] ) ? $ matches [ 4 ] : null , $ a ) ) { return self :: fromHsl ( $ h , $ s , $ l , $ a ) ; } $ result = self :: parseNamedColor ( $ value ) ; if ( $ result !== null ) { return $ result ; } throw new \ InvalidArgumentException ( "Cannot parse '$value' as a color." ) ; }
|
Tries to parse a value as a Color .
|
50,754
|
private static function parsePercent ( $ input , & $ result ) { if ( preg_match ( '/^\\s*(\\d*(?:\\.\\d*)?)%\\s*$/' , $ input , $ matches ) ) { $ result = floatval ( $ matches [ 1 ] ) / 100 ; if ( $ result < 0 ) $ result = 0 ; if ( $ result > 1 ) $ result = 1 ; return true ; } return false ; }
|
Parses a percent value .
|
50,755
|
private static function parseAlpha ( $ input , & $ result ) { if ( $ input === null || $ input === '' ) { $ result = 1 ; return true ; } if ( preg_match ( '/^\\s*(\\d*(?:\\.\\d*)?)(%?)\\s*$/' , $ input , $ matches ) ) { $ result = floatval ( $ matches [ 1 ] ) ; if ( $ matches [ 2 ] !== '' ) { $ result = $ result / 100 ; } if ( $ result < 0 ) $ result = 0 ; if ( $ result > 1 ) $ result = 1 ; return true ; } return false ; }
|
Parses an alpha value .
|
50,756
|
private static function parseRgbComponent ( $ input , & $ result ) { if ( preg_match ( '/^\\s*(\\d*(?:\\.\\d*)?)(%?)\\s*$/' , $ input , $ matches ) ) { $ result = floatval ( $ matches [ 1 ] ) ; if ( $ matches [ 2 ] === '%' ) { $ result = 255 * $ result / 100 ; } $ result = ( int ) $ result ; if ( $ result < 0 ) $ result = 0 ; if ( $ result > 255 ) $ result = 255 ; return true ; } return false ; }
|
Parses an RGB component .
|
50,757
|
private static function parseHue ( $ input , & $ result ) { if ( preg_match ( '/^\s*(\d*(?:\.\d*)?)(deg|grad|rad|turn|)\s*$/' , $ input , $ matches ) ) { $ result = floatval ( $ matches [ 1 ] ) ; switch ( $ matches [ 2 ] ) { case "grad" : $ result = $ result / 400 ; break ; case "rad" : $ result = $ result / M_PI / 2 ; break ; case "turn" : $ result = $ result ; break ; default : $ result = $ result / 360 ; break ; } $ result = fmod ( $ result , 1 ) ; if ( $ result < 0 ) { $ result += 1 ; } return true ; } return false ; }
|
Parses a hue component .
|
50,758
|
private static function parseHexColor ( $ input , & $ result ) { if ( $ input [ 0 ] === '#' ) { $ input = substr ( $ input , 1 ) ; } $ numeric24bit = intval ( substr ( $ input , 0 , 6 ) , 16 ) ; $ alpha8bit = intval ( substr ( $ input , 6 , 2 ) , 16 ) ; switch ( strlen ( $ input ) ) { case 3 : $ result = self :: fromRgb ( ( ( $ numeric24bit & 0xf00 ) >> 8 ) | ( ( $ numeric24bit & 0xf00 ) >> 4 ) , ( ( $ numeric24bit & 0x0f0 ) >> 4 ) | ( ( $ numeric24bit & 0x0f0 ) ) , ( ( $ numeric24bit & 0x00f ) << 4 ) | ( ( $ numeric24bit & 0x00f ) ) ) ; return true ; case 4 : $ result = self :: fromRgb ( ( ( $ numeric24bit & 0xf000 ) >> 12 ) | ( ( $ numeric24bit & 0xf000 ) >> 8 ) , ( ( $ numeric24bit & 0x0f00 ) >> 8 ) | ( ( $ numeric24bit & 0x0f00 ) >> 4 ) , ( ( $ numeric24bit & 0x00f0 ) >> 4 ) | ( ( $ numeric24bit & 0x00f0 ) ) , ( ( $ numeric24bit & 0x000f ) << 4 ) | ( ( $ numeric24bit & 0x000f ) ) ) ; return true ; case 6 : $ result = self :: fromRgb ( 0xff & ( $ numeric24bit >> 16 ) , 0xff & ( $ numeric24bit >> 8 ) , 0xff & ( $ numeric24bit ) ) ; return true ; case 8 : $ result = self :: fromRgb ( 0xff & ( $ numeric24bit >> 16 ) , 0xff & ( $ numeric24bit >> 8 ) , 0xff & ( $ numeric24bit ) , 0xff & ( $ alpha8bit ) ) ; return true ; } return false ; }
|
Parses a hex color string .
|
50,759
|
public function setTransform ( \ Jdenticon \ Rendering \ Transform $ transform ) { $ this -> transform = $ transform === null ? Transform :: getEmpty ( ) : $ transform ; }
|
Sets the current transform that will be applied on all coordinates before being rendered to the target image .
|
50,760
|
public function addRectangle ( $ x , $ y , $ width , $ height , $ invert = false ) { $ this -> addPolygonCore ( array ( new Point ( $ x , $ y ) , new Point ( $ x + $ width , $ y ) , new Point ( $ x + $ width , $ y + $ height ) , new Point ( $ x , $ y + $ height ) , ) , $ invert ) ; }
|
Adds a rectangle to the image .
|
50,761
|
public function addCircle ( $ x , $ y , $ size , $ invert = false ) { $ northWest = $ this -> transform -> transformPoint ( $ x , $ y , $ size , $ size ) ; $ this -> addCircleNoTransform ( $ northWest -> x , $ northWest -> y , $ size , $ invert ) ; }
|
Adds a circle to the image .
|
50,762
|
public function addTriangle ( $ x , $ y , $ width , $ height , $ direction , $ invert = false ) { $ points = array ( new Point ( $ x + $ width , $ y ) , new Point ( $ x + $ width , $ y + $ height ) , new Point ( $ x , $ y + $ height ) , new Point ( $ x , $ y ) ) ; array_splice ( $ points , $ direction , 1 ) ; $ this -> addPolygonCore ( $ points , $ invert ) ; }
|
Adds a triangle to the image .
|
50,763
|
public function transformPoint ( $ x , $ y , $ width = 0 , $ height = 0 ) { $ right = $ this -> x + $ this -> size ; $ bottom = $ this -> y + $ this -> size ; switch ( $ this -> rotation ) { case 1 : return new Point ( $ right - $ y - $ height , $ this -> y + $ x ) ; case 2 : return new Point ( $ right - $ x - $ width , $ bottom - $ y - $ height ) ; case 3 : return new Point ( $ this -> x + $ y , $ bottom - $ x - $ width ) ; default : return new Point ( $ this -> x + $ x , $ this -> y + $ y ) ; } }
|
Transforms the specified point based on the translation and rotation specification for this Transform .
|
50,764
|
public function add ( \ Jdenticon \ Canvas \ Rasterization \ Edge $ edge ) { $ minY = 0 ; $ maxY = 0 ; if ( $ edge -> y0 == $ edge -> y1 ) { return ; } elseif ( $ edge -> y0 < $ edge -> y1 ) { $ minY = ( int ) ( $ edge -> y0 ) ; $ maxY = ( int ) ( $ edge -> y1 + 0.996 ) ; } else { $ minY = ( int ) ( $ edge -> y1 ) ; $ maxY = ( int ) ( $ edge -> y0 + 0.996 ) ; } if ( $ maxY < 0 || $ minY >= $ this -> height ) { return ; } if ( $ minY < 0 ) { $ minY = 0 ; } if ( $ maxY > $ this -> height ) { $ maxY = $ this -> height ; } if ( $ minY < $ maxY ) { $ y = $ minY ; $ x1 = $ edge -> intersection ( $ y ) ; while ( $ y < $ maxY ) { $ x2 = $ edge -> intersection ( $ y + 1 ) ; $ fromX ; $ width ; if ( $ x1 < $ x2 ) { $ fromX = ( int ) ( $ x1 ) ; $ width = ( int ) ( $ x2 + 0.9999 ) - $ fromX ; } else { $ fromX = ( int ) ( $ x2 ) ; $ width = ( int ) ( $ x1 + 0.9999 ) - $ fromX ; } if ( $ fromX < 0 ) { $ width += $ fromX ; $ fromX = 0 ; if ( $ width < 0 ) { $ width = 0 ; } } if ( $ fromX < $ this -> width ) { if ( ! isset ( $ this -> scanlines [ $ y ] ) ) { $ this -> scanlines [ $ y ] = array ( ) ; } $ this -> scanlines [ $ y ] [ ] = new EdgeIntersection ( $ fromX , $ width , $ edge ) ; } $ x1 = $ x2 ; $ y ++ ; } } }
|
Adds an edge to the table .
|
50,765
|
public function multiply ( $ a , $ b , $ c , $ d , $ e , $ f ) { return new Matrix ( $ this -> a * $ a + $ this -> c * $ b , $ this -> b * $ a + $ this -> d * $ b , $ this -> a * $ c + $ this -> c * $ d , $ this -> b * $ c + $ this -> d * $ d , $ this -> a * $ e + $ this -> c * $ f + $ this -> e , $ this -> b * $ e + $ this -> d * $ f + $ this -> f ) ; }
|
Returns a new matrix based on the current matrix multiplied with the specified matrix values .
|
50,766
|
public function multiplyPoint ( $ x , $ y ) { return new Point ( $ this -> a * $ x + $ this -> c * $ y + $ this -> e , $ this -> b * $ x + $ this -> d * $ y + $ this -> f ) ; }
|
Multiplies the specified point with the current matrix and returns the resulting point .
|
50,767
|
public function rotate ( $ angle ) { $ sin = sin ( $ angle ) ; $ cos = cos ( $ angle ) ; return $ this -> multiply ( $ cos , $ sin , - $ sin , $ cos , 0 , 0 ) ; }
|
Returns a new matrix based on the current matrix with a rotation transformation applied .
|
50,768
|
public static function mix ( $ color1 , $ color2 , $ weight ) { if ( $ weight < 0 ) { $ weight = 0 ; } elseif ( $ weight > 1 ) { $ weight = 1 ; } $ a = ( $ color1 & 0xff ) * ( 1 - $ weight ) + ( $ color2 & 0xff ) * $ weight ; if ( $ a <= 0.1 ) { return 0 ; } $ r = ( ( $ color1 >> 24 ) * ( $ color1 & 0xff ) * ( 1 - $ weight ) + ( $ color2 >> 24 ) * ( $ color2 & 0xff ) * $ weight ) / $ a ; $ g = ( ( ( $ color1 >> 16 ) & 0xff ) * ( $ color1 & 0xff ) * ( 1 - $ weight ) + ( ( $ color2 >> 16 ) & 0xff ) * ( $ color2 & 0xff ) * $ weight ) / $ a ; $ b = ( ( ( $ color1 >> 8 ) & 0xff ) * ( $ color1 & 0xff ) * ( 1 - $ weight ) + ( ( $ color2 >> 8 ) & 0xff ) * ( $ color2 & 0xff ) * $ weight ) / $ a ; if ( $ a > 255 ) $ a = 255 ; if ( $ r > 255 ) $ r = 255 ; if ( $ g > 255 ) $ g = 255 ; if ( $ b > 255 ) $ b = 255 ; return ( ( int ) $ r << 24 ) | ( ( int ) $ g << 16 ) | ( ( int ) $ b << 8 ) | ( int ) $ a ; }
|
Computes a mix of the two specified colors with the proportion given by the specified weight .
|
50,769
|
public static function parse ( $ color ) { if ( gettype ( $ color ) == "integer" ) { return $ color & 0xffffffff ; } $ color = "$color" ; if ( preg_match ( '/^#?[0-9a-fA-F]+$/' , $ color ) ) { $ hexColor = $ color ; if ( $ hexColor [ 0 ] == '#' ) { $ hexColor = substr ( $ hexColor , 1 ) ; } switch ( strlen ( $ hexColor ) ) { case 3 : $ numeric = intval ( $ hexColor , 16 ) ; return ( ( ( $ numeric & 0xf00 ) << 20 ) | ( ( $ numeric & 0xf00 ) << 16 ) | ( ( $ numeric & 0x0f0 ) << 16 ) | ( ( $ numeric & 0x0f0 ) << 12 ) | ( ( $ numeric & 0x00f ) << 12 ) | ( ( $ numeric & 0x00f ) << 8 ) | 0xff ) ; case 6 : return ( intval ( $ hexColor , 16 ) << 8 ) | 0xff ; case 8 : $ numeric = ( intval ( substr ( $ hexColor , 0 , 4 ) , 16 ) << 16 ) | ( intval ( substr ( $ hexColor , 4 , 4 ) , 16 ) ) ; return $ numeric ; } } throw new \ InvalidArgumentException ( "Invalid color '$color'." ) ; }
|
Parses a value to a 32 - bit color on the format 0xRRGGBBAA .
|
50,770
|
public static function over ( $ fore , $ back ) { $ foreA = ( $ fore & 0xff ) ; $ backA = ( $ back & 0xff ) ; if ( $ foreA < 1 ) { return $ back ; } elseif ( $ foreA > 254 || $ backA < 1 ) { return $ fore ; } $ forePA = $ foreA * 255 ; $ backPA = $ backA * ( 255 - $ foreA ) ; $ pa = ( $ forePA + $ backPA ) ; $ b = ( ( $ forePA * ( ( $ fore >> 8 ) & 0xff ) + $ backPA * ( ( $ back >> 8 ) & 0xff ) ) / $ pa ) ; $ g = ( ( $ forePA * ( ( $ fore >> 16 ) & 0xff ) + $ backPA * ( ( $ back >> 16 ) & 0xff ) ) / $ pa ) ; $ r = ( ( $ forePA * ( ( $ fore >> 24 ) & 0xff ) + $ backPA * ( ( $ back >> 24 ) & 0xff ) ) / $ pa ) ; $ a = ( $ pa / 255 ) ; return ( $ r << 24 ) | ( $ g << 16 ) | ( $ b << 8 ) | $ a ; }
|
Blends this color with another color using the over blending operation .
|
50,771
|
public function restore ( ) { $ state = array_pop ( $ this -> savedStates ) ; if ( $ state != NULL ) { $ this -> transform = $ state [ 'transform' ] ; $ this -> fillStyle = $ state [ 'fillStyle' ] ; } }
|
Restores the last saved state of the CanvasContext .
|
50,772
|
public function transform ( $ a , $ b , $ c , $ d , $ e , $ f ) { if ( gettype ( $ a ) != 'integer' || gettype ( $ b ) != 'integer' || gettype ( $ c ) != 'integer' || gettype ( $ d ) != 'integer' || gettype ( $ e ) != 'integer' || gettype ( $ f ) != 'integer' ) { return ; } $ this -> transform = $ this -> transform -> multiply ( $ a , $ b , $ c , $ d , $ e , $ f ) ; }
|
Multiplies the current transformation matrix with the specified values .
|
50,773
|
public function setTransform ( $ a , $ b , $ c , $ d , $ e , $ f ) { if ( gettype ( $ a ) != 'integer' || gettype ( $ b ) != 'integer' || gettype ( $ c ) != 'integer' || gettype ( $ d ) != 'integer' || gettype ( $ e ) != 'integer' || gettype ( $ f ) != 'integer' ) { return ; } $ this -> transform = new Matrix ( $ a , $ b , $ c , $ d , $ e , $ f ) ; }
|
Sets the transformation matrix to the specified matrix .
|
50,774
|
public function translate ( $ x , $ y ) { $ this -> transform = $ this -> transform -> translate ( $ x , $ y ) ; }
|
Applies a translation transformation to the CanvasContext .
|
50,775
|
public function scale ( $ x , $ y ) { $ this -> transform = $ this -> transform -> scale ( $ x , $ y ) ; }
|
Applies a scale transformation to the CanvasContext .
|
50,776
|
public function closePath ( ) { $ pathsCount = count ( $ this -> paths ) ; if ( $ pathsCount > 0 ) { $ path = $ this -> paths [ $ pathsCount - 1 ] ; $ pathCount = count ( $ path ) ; if ( $ pathCount > 2 ) { if ( $ path [ 0 ] != $ path [ $ pathCount - 2 ] || $ path [ 1 ] != $ path [ $ pathCount - 1 ] ) { $ path [ ] = $ path [ 0 ] ; $ path [ ] = $ path [ 1 ] ; } $ this -> paths [ ] = array ( $ path [ 0 ] , $ path [ 1 ] ) ; } } }
|
Starts a new subpath that begins in the same point as the start and end point of the previous one .
|
50,777
|
public function moveTo ( $ x , $ y ) { $ p = $ this -> transform -> multiplyPoint ( $ x , $ y ) ; $ this -> paths [ ] = array ( $ p -> x , $ p -> y ) ; }
|
Begins a new subpath by moving the cursor to the specified position .
|
50,778
|
public function lineTo ( $ x , $ y ) { $ pathsCount = count ( $ this -> paths ) ; if ( $ pathsCount == 0 ) { $ this -> paths [ ] = array ( ) ; $ pathsCount ++ ; } $ p = $ this -> transform -> multiplyPoint ( $ x , $ y ) ; $ path = & $ this -> paths [ $ pathsCount - 1 ] ; $ path [ ] = $ p -> x ; $ path [ ] = $ p -> y ; }
|
Inserts an edge between the last and specified position .
|
50,779
|
public function arc ( $ x , $ y , $ radius , $ startAngle , $ endAngle , $ anticlockwise ) { $ TARGET_CHORD_LENGTH_PIXELS = 3 ; $ sectors = floor ( ( M_PI * $ radius * 2 ) / $ TARGET_CHORD_LENGTH_PIXELS ) ; if ( $ sectors < 9 ) { $ sectors = 9 ; } $ sectorAngle = M_PI * 2 / $ sectors ; if ( $ startAngle == $ endAngle ) { return ; } if ( $ anticlockwise ) { $ sectorAngle = - $ sectorAngle ; if ( $ startAngle - $ endAngle >= M_PI * 2 ) { $ endAngle = $ startAngle - M_PI * 2 ; } else { $ endAngle += M_PI * 2 * ceil ( ( $ startAngle - $ endAngle ) / ( M_PI * 2 ) - 1 ) ; } } else { if ( $ endAngle - $ startAngle >= M_PI * 2 ) { $ endAngle = $ startAngle + M_PI * 2 ; } else { $ endAngle -= M_PI * 2 * ceil ( ( $ endAngle - $ startAngle ) / ( M_PI * 2 ) - 1 ) ; } } $ dx ; $ dy ; $ sectors = ( $ endAngle - $ startAngle ) / $ sectorAngle ; $ angle = $ startAngle ; for ( $ i = 0 ; $ i < $ sectors ; $ i ++ ) { $ dx = cos ( $ angle ) * $ radius ; $ dy = sin ( $ angle ) * $ radius ; $ this -> lineTo ( $ x + $ dx , $ y + $ dy ) ; $ angle += $ sectorAngle ; } $ dx = cos ( $ endAngle ) * $ radius ; $ dy = sin ( $ endAngle ) * $ radius ; $ this -> lineTo ( $ x + $ dx , $ y + $ dy ) ; }
|
Adds an arc to the current path .
|
50,780
|
public function clearRect ( $ x , $ y , $ width , $ height ) { $ fullCanvas = false ; if ( ! $ this -> transform -> hasSkewing ( ) ) { $ topLeft = $ this -> transform -> multiplyPoint ( $ x , $ y ) ; if ( $ topLeft -> x <= 0 && $ topLeft -> y <= 0 ) { $ bottomRight = $ this -> transform -> multiplyPoint ( $ x + $ width , $ y + $ height ) ; if ( $ bottomRight -> x >= $ this -> canvas -> width && $ bottomRight -> y >= $ this -> canvas -> height ) { $ fullCanvas = true ; } } } if ( $ fullCanvas ) { $ this -> edges -> clear ( ) ; } else { $ this -> _fillRect ( ColorUtils :: FORCE_TRANSPARENT , $ x , $ y , $ width , $ height ) ; } }
|
Fills the specified rectangle with fully transparent black without affecting the current paths .
|
50,781
|
public function fillRect ( $ x , $ y , $ width , $ height ) { $ fillColor = ColorUtils :: parse ( $ this -> fillStyle ) ; $ this -> _fillRect ( $ fillColor , $ x , $ y , $ width , $ height ) ; }
|
Fills the specified rectangle without affecting the current paths .
|
50,782
|
public function fill ( $ windingRule = "nonzero" ) { $ polygonId = $ this -> edges -> getNextPolygonId ( ) ; $ fillColor = ColorUtils :: parse ( $ this -> fillStyle ) ; foreach ( $ this -> paths as $ points ) { $ pointsCount = count ( $ points ) ; if ( $ pointsCount <= 2 ) { continue ; } for ( $ i = 2 ; $ i < $ pointsCount ; $ i += 2 ) { $ this -> edges -> add ( new Edge ( $ polygonId , $ points [ $ i - 2 ] , $ points [ $ i - 1 ] , $ points [ $ i ] , $ points [ $ i + 1 ] , $ fillColor , $ windingRule ) ) ; } if ( $ points [ 0 ] != $ points [ $ pointsCount - 2 ] || $ points [ 1 ] != $ points [ $ pointsCount - 1 ] ) { $ this -> edges -> add ( new Edge ( $ polygonId , $ points [ $ pointsCount - 2 ] , $ points [ $ pointsCount - 1 ] , $ points [ 0 ] , $ points [ 1 ] , $ fillColor , $ windingRule ) ) ; } } }
|
Fills the defined paths .
|
50,783
|
public function getOptions ( ) { $ options = array ( ) ; $ options [ 'backgroundColor' ] = $ this -> getBackgroundColor ( ) -> __toString ( ) ; $ options [ 'padding' ] = $ this -> getPadding ( ) ; $ options [ 'colorSaturation' ] = $ this -> getColorSaturation ( ) ; $ options [ 'grayscaleSaturation' ] = $ this -> getGrayscaleSaturation ( ) ; $ options [ 'colorLightness' ] = $ this -> getColorLightness ( ) ; $ options [ 'grayscaleLightness' ] = $ this -> getGrayscaleLightness ( ) ; if ( $ this -> hues !== null ) { $ options [ 'hues' ] = $ this -> getHues ( ) ; } return $ options ; }
|
Gets an associative array of all options of this style .
|
50,784
|
private static function normalizeHue ( $ hue ) { if ( ! is_numeric ( $ hue ) ) { throw new \ InvalidArgumentException ( "'$hue' is not a valid hue." ) ; } $ hue = $ hue % 360 ; if ( $ hue < 0 ) { $ hue += 360 ; } return $ hue ; }
|
Normalizes a hue to the first turn [ 0 360 ) .
|
50,785
|
public function setHues ( $ value ) { $ hues = array ( ) ; if ( $ value !== null ) { if ( is_array ( $ value ) ) { foreach ( $ value as $ hue ) { $ hues [ ] = self :: normalizeHue ( $ hue ) ; } } else { $ hues [ ] = self :: normalizeHue ( $ value ) ; } } $ this -> hues = empty ( $ hues ) ? null : $ hues ; return $ this ; }
|
Sets the allowed hues of generated icons .
|
50,786
|
public function setPadding ( $ value ) { if ( ! is_numeric ( $ value ) || $ value < 0 || $ value > 0.4 ) { throw new \ InvalidArgumentException ( "Padding '$value' out of range. " . "Values in the range [0.0, 0.4] are allowed." ) ; } $ this -> padding = ( float ) $ value ; return $ this ; }
|
Sets the padding of an icon in percents .
|
50,787
|
public function setBackgroundColor ( $ value ) { if ( $ value instanceof Color ) { $ this -> backgroundColor = $ value ; } else { $ this -> backgroundColor = Color :: parse ( $ value ) ; } return $ this ; }
|
Sets the color of the identicon background .
|
50,788
|
public function setGrayscaleSaturation ( $ value ) { if ( ! is_numeric ( $ value ) || $ value < 0 || $ value > 1 ) { throw new \ InvalidArgumentException ( "The grayscale saturation was invalid. " . "Only values in the range [0.0, 1.0] are allowed." ) ; } $ this -> grayscaleSaturation = ( float ) $ value ; return $ this ; }
|
Sets the saturation of the originally grayscale identicon shapes .
|
50,789
|
public function setColorSaturation ( $ value ) { if ( ! is_numeric ( $ value ) || $ value < 0 || $ value > 1 ) { throw new \ InvalidArgumentException ( "The color saturation was invalid. " . "Only values in the range [0.0, 1.0] are allowed." ) ; } $ this -> colorSaturation = ( float ) $ value ; return $ this ; }
|
Sets the saturation of the colored identicon shapes .
|
50,790
|
public function setColorLightness ( $ value ) { if ( ! is_array ( $ value ) || ! array_key_exists ( 0 , $ value ) || ! array_key_exists ( 1 , $ value ) || ! is_numeric ( $ value [ 0 ] ) || ! is_numeric ( $ value [ 1 ] ) || $ value [ 0 ] < 0 || $ value [ 0 ] > 1 || $ value [ 1 ] < 0 || $ value [ 1 ] > 1 ) { throw new \ InvalidArgumentException ( "The value passed to setColorLightness was invalid. " . "Please check the documentation." ) ; } $ this -> colorLightness = array ( ( float ) $ value [ 0 ] , ( float ) $ value [ 1 ] ) ; return $ this ; }
|
Sets the value of the ColorLightness property .
|
50,791
|
public function setGrayscaleLightness ( $ value ) { if ( ! is_array ( $ value ) || ! array_key_exists ( 0 , $ value ) || ! array_key_exists ( 1 , $ value ) || ! is_numeric ( $ value [ 0 ] ) || ! is_numeric ( $ value [ 1 ] ) || $ value [ 0 ] < 0 || $ value [ 0 ] > 1 || $ value [ 1 ] < 0 || $ value [ 1 ] > 1 ) { throw new \ InvalidArgumentException ( "The value passed to setGrayscaleLightness was invalid. " . "Please check the documentation." ) ; } $ this -> grayscaleLightness = array ( ( float ) $ value [ 0 ] , ( float ) $ value [ 1 ] ) ; return $ this ; }
|
Sets the value of the GrayscaleLightness property .
|
50,792
|
public function endChunk ( ) { $ data = $ this -> buffer ; $ crc = crc32 ( $ data ) ; $ this -> buffer = $ this -> chunkPreviousBuffer . pack ( 'N' , strlen ( $ data ) - 4 ) . $ data . pack ( 'N' , $ crc ) ; }
|
Closes the current PNG chunk .
|
50,793
|
public function getAuthenticationUrl ( ) { $ params = [ 'client_id' => $ this -> clientId , 'scope' => $ this -> scopes , 'state' => $ this -> state , 'response_type' => 'code' , 'redirect_uri' => $ this -> redirectUrl , ] ; return 'https://medium.com/m/oauth/authorize?' . http_build_query ( $ params ) ; }
|
Get the url to authenticate the user to medium .
|
50,794
|
public function createPost ( $ authorId , array $ data ) { $ requestData = [ 'form_params' => $ data , ] ; return $ this -> client -> makeRequest ( 'POST' , 'users/' . $ authorId . '/posts' , $ requestData ) ; }
|
Create a post on the authenticated user s profile .
|
50,795
|
public function createPostUnderPublication ( $ publicationId , array $ data ) { $ requestData = [ 'form_params' => $ data , ] ; return $ this -> client -> makeRequest ( 'POST' , 'publications/' . $ publicationId . '/posts' , $ requestData ) ; }
|
Create a post under a publication on the authenticated user s profile .
|
50,796
|
private function setUpCredentials ( $ credentials ) { if ( is_array ( $ credentials ) ) { $ this -> clientId = $ credentials [ 'client-id' ] ; $ this -> clientSecret = $ credentials [ 'client-secret' ] ; $ this -> redirectUrl = $ credentials [ 'redirect-url' ] ; $ this -> state = $ credentials [ 'state' ] ; $ this -> scopes = $ credentials [ 'scopes' ] ; } else { $ this -> accessToken = $ credentials ; } }
|
Setup initial api credentials .
|
50,797
|
private function setBasicApiClient ( ) { $ this -> client = new Client ( ) ; if ( ! is_null ( $ this -> accessToken ) ) { $ this -> client -> authenticate ( $ this -> accessToken ) ; } }
|
Minimal setup for medium s api client . Just get it ready to request for access tokens .
|
50,798
|
public function requestTokens ( $ authorizationCode , $ clientId , $ clientSecret , $ redirectUrl ) { $ data = [ 'form_params' => [ 'code' => $ authorizationCode , 'client_id' => $ clientId , 'client_secret' => $ clientSecret , 'grant_type' => 'authorization_code' , 'redirect_uri' => $ redirectUrl , ] , ] ; $ client = new GuzzleClient ( [ 'base_uri' => $ this -> url , 'exceptions' => false , 'headers' => [ 'Content-Type' => 'application/json' , 'Accept' => 'application/json' , 'Accept-Charset' => 'utf-8' , ] , ] ) ; $ response = $ client -> request ( 'POST' , 'tokens' , $ data ) ; return json_decode ( ( string ) $ response -> getBody ( ) ) ; }
|
Ask medium for the access and refresh token using the provided authorization code .
|
50,799
|
public function makeRequest ( $ method , $ endpoint , array $ data = [ ] ) { $ response = $ this -> client -> request ( $ method , $ endpoint , $ data ) ; return json_decode ( ( string ) $ response -> getBody ( ) ) ; }
|
Make a request to medium s api .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.