📜 ⬆️ ⬇️

Vertical text

I needed to use a vertical text layout to designate the table headings. Searches on the Internet have led only to outdated or not yet approved standards, IE filters and not supporting Cyrillic or Mozilla Firefox SVG.
Therefore, I had to solve the problem myself. A little ugly happened, but the result gave me.

image


function vtext ( $text ) //
{
if ( ! file_exists ( _SITE . '/style/img/crap/' . str2url ( $text ) . '.png' ) ) {
// echo ' '.str2url($text).'.png<br /><br />';
$pname = str2url ( $text ) ;
$txt = win2uni ( $text ) ;
$coord = imagettfbbox ( _FONT_SIZE , 0 , _FONT_NAME , $txt ) ;
/* , , . :
*/

$width = $coord [ 2 ] - $coord [ 0 ] ;
$height = $coord [ 1 ] - $coord [ 7 ] ;

$im = ImageCreate ( $width , $height + ( _FONT_SIZE / 4 ) ) ;
$background_color = ImageColorAllocate ( $im , 255 , 255 , 255 ) ;
$text_color = ImageColorAllocate ( $im , 0 , 0 , 0 ) ;

imagettftext ( $im , _FONT_SIZE , 0 , 0 - ( _FONT_SIZE / 10 ) , $height , $text_color , _FONT_NAME , $txt ) ;
$im2 = imagerotate ( $im , 90 , 0 ) ;
ImagePNG ( $im2 , $_SERVER [ 'DOCUMENT_ROOT' ] . '/style/img/crap/' . $pname . '.png' ) ;
ImageDestroy ( $im ) ;
ImageDestroy ( $im2 ) ;
$to_return = '<img src="' . _SITE . '/style/img/crap/' . $pname . '.png" />' ;
echo $to_return ;
}
}
function win2uni ( $s )
{
$s = str_replace ( 'і' , 'i' , $s ) ;
$s = str_replace ( 'І' , 'I' , $s ) ;
$s = convert_cyr_string ( $s , 'w' , 'i' ) ; // win1251 -> iso8859-5
// iso8859-5 -> unicode:
for ( $result = '' , $i = 0 ; $i < strlen ( $s ) ; $i ++ ) {
$charcode = ord ( $s [ $i ] ) ;
$result .= ( $charcode > 175 ) ? "&#" . ( 1040 + ( $charcode - 176 ) ) . ";" : $s [ $i ] ;
}
return $result ;
}


Use - it is natural to call a function with a parameter - text that needs to be rotated.
vtext ( ' ' ) ;

The only thing - does not work with the entire Ukrainian alphabet. Partially corrected by replacing the Ukrainian "i" with the English "i". If there are options to fix this problem - tell me.
If there is an option to make it easier - tell me.
')
PS To create file names using the transliteration function:
<?php
function rus2translit($string) {
$converter = array(
'' => 'a', '' => 'b', '' => 'v',
'' => 'g', '' => 'd', '' => 'e',
'' => 'e', '' => 'zh', '' => 'z',
'' => 'i', '' => 'y', '' => 'k',
'' => 'l', '' => 'm', '' => 'n',
'' => 'o', '' => 'p', '' => 'r',
'' => 's', '' => 't', '' => 'u',
'' => 'f', '' => 'h', '' => 'c',
'' => 'ch', '' => 'sh', '' => 'sch',
'' => '\'', '' => 'y', '' => '\'',
'' => 'e', '' => 'yu', '' => 'ya',
'і' => 'ui', 'ї' => 'uyi', 'є' => 'uye',
'ґ'=>'ugi',

'' => 'A', '' => 'B', '' => 'V',
'' => 'G', '' => 'D', '' => 'E',
'' => 'E', '' => 'Zh', '' => 'Z',
'' => 'I', '' => 'Y', '' => 'K',
'' => 'L', '' => 'M', '' => 'N',
'' => 'O', '' => 'P', '' => 'R',
'' => 'S', '' => 'T', '' => 'U',
'' => 'F', '' => 'H', '' => 'C',
'' => 'Ch', '' => 'Sh', '' => 'Sch',
'' => '\'', '' => 'Y', '' => '\'',
'' => 'E', '' => 'Yu', '' => 'Ya',
'І' => 'uI', 'Ї'=>'uYi', 'Є'=>'uYe',
'Ґ'=>'uGi'
);
return strtr($string, $converter);
}
function str2url($str) {
//
$str = rus2translit($str);
//
$str = strtolower($str);
// "-"
$str = preg_replace('~[^-a-z0-9_.]+~u', '-', $str);
// '-'
$str = trim($str, "-");
return $str;
}
?>


Source: https://habr.com/ru/post/51438/


All Articles