Question

I asked in past, but I am not sure we understand & I still havent solution. I need elegant solution when; I have photo 600x800 & I need show it on my site rotated on 90 degrees, so result will be, when I print php page all photos will be verticaly automaticly.

e.g. I have a lot of photos, two kinds: 800x600 & 600x800. I need on my php page showed all of them 800x600 in original and all 600x800 rotated on 90 degrees.

I need some really simple solution, I am out of mind totally. Some function which can rotate images which have bigger width than height.

Thanks a lot.

Was it helpful?

Solution

Using PHP function getimagesize() you can get width and height of your image:

  list($width, $height) = getimagesize($imageUrl);

Then, in your template:

  <?php if($width > $height): ?>
        //put css here as you want
  <?php else: ?>
        //put css here as you want
  <?php endif; ?>

OTHER TIPS

Use getimagesize for detect image width and if width is 800px add inline css like this

style="-moz-transform: rotate(90deg); -webkit-transform: rotate(90deg); -o-transform: rotate(90deg); -ms-transform: rotate(90deg); transform: rotate(90deg);"

getimagesize() function will give you width and height and by using imagerotate() you can rotate that image to any desired angle.

Try this:-

<?php
// File and rotation
$filename = 'php.jpg';
$degrees = 180;

// Content type
header('Content-type: image/jpeg');

// Load
$source = imagecreatefromjpeg($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

// Output
imagejpeg($rotate);

// Free the memory
imagedestroy($source);
imagedestroy($rotate);
?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top