У меня есть определенная фиксированная ширина и высота, чтобы изменить размер изображения. Однако у меня проблема с этим, потому что изображение может иметь любое отношение размеров (оно может быть вертикально или горизонтально). В этом случае фиксированная ширина и высота создают проблему. Я хочу рассчитать ширину и высоту более разумным способом.
Например, скажем, я определил ширину 1024px и высоту 768px. И я хочу изменить размер вертикального изображения (высота 1100 пикселей и ширина 200 пикселей). Так что в моем случае он изменит размер до фиксированного размера (1024x768), поэтому ширина будет увеличена с 100 пикселей до 768 пикселей, и это будет очень уродливо. Аналогично, если изображение имеет высоту менее 768px, оно будет увеличивать высоту силой до 768px.
Поэтому я хотел бы рассчитать новый размер изображения на основе исходного соотношения размеров изображения. Допустим, если изображение вышеприведенного изображения должно быть изменено до максимальной высоты 768px, но тогда, что же касается ширины? он уже меньше моей "максимальной ширины", которая 200px, поэтому ширина должна оставаться неизменной? или его дальнейшее снижение?
Аналогично, если изображение имеет высоту 200px и ширину 1100px. Поэтому ширина должна быть уменьшена до 1024px, но как насчет высоты?
Третья проблема заключается в том, что предположим, что если высота и ширина больше максимальной высоты и максимальной ширины, скажем ширина: 1100 пикселей и высота: 4000 пикселей. Теперь, поскольку ширина и высота не превышают максимальную ширину и максимальную высоту, но изображение вертикальное, оно будет горизонтальным. Итак, как я могу проверить, если в этом случае, если я должен изменить размер изображения в соответствии с максимальной высотой или в соответствии с максимальной шириной?
Я ценю любую помощь в этом.