Autor | Zpráva | ||
---|---|---|---|
maxx Profil * |
#1 · Zasláno: 1. 4. 2009, 18:56:22
Zdravim,
nevim jestli mi to teď vůbec nemyslí, nebo jsem prostě tak tupej, ale nejsem schopnej si napsat výpočet šířky a výšky u obrázku. Když např. zadam rozměry: šířka - 130px a výška - 160px a uploadnu obrázek, tak aby mi to upravilo vždy na rozměry např. 130x190, 130x250, 150x160, 138x160, apod. Mám tohle: $newWidth = 130; $aspect = $width / $height; $newHeight = round( $newWidth/$aspect ); Ale to funguje pouze když je např. rozměr 450x600. nejsem do toho schopnej zakomponovat další úpravu. Dík za nakopnutí, či postnutí hotovýho řešení. |
||
Alphard Profil |
#2 · Zasláno: 1. 4. 2009, 19:01:55
function image_shrink_size($file_in, $max_x = 0, $max_y = 0) { list($width, $height) = getimagesize($file_in); if (!$width || !$height) { return array(0, 0); } if ($max_x && $width > $max_x) { $height = round($height * $max_x / $width); $width = $max_x; } if ($max_y && $height > $max_y) { $width = round($width * $max_y / $height); $height = $max_y; } return array($width, $height); } http://php.vrana.cz/zmensovani-obrazku.php |
||
maxx Profil * |
#3 · Zasláno: 1. 4. 2009, 19:20:47
To znám, ale to bohužel neřeší můj problém. Tohle vždy upraví strany na maximální. Tudíž ta jedna strana je menší než těch 130px nebo 160px. Ale já potřebuju aby to vždy bylo větší. Tudíž šířka bude mít 130px a druhá např. 170,180, 195, atd. To stejný obráceně. Výška se upraví na 160 a druhá strana musí mít víc jak 130. Tedy 140 nebo např. 150. Snad jsem to popsal pořádně.
|
||
Alphard Profil |
#4 · Zasláno: 1. 4. 2009, 21:34:57
takhle?
function image_shrink_size($file_in, $max_x = 0, $max_y = 0) { list($width, $height) = getimagesize($file_in); if (!$width || !$height) { return array(0, 0); } if ($height < $width) { $width = round($width * $max_y / $height); $height = $max_y; } elseif ($height > $width) { $height = round($height * $max_x / $width); $width = $max_x; } else { $width = $max_x; $height = $max_y; } return array($width, $height); } |
||
Časová prodleva: 15 let
|
0