Note that there are some explanatory texts on larger screens.

plurals
  1. POUpload image without losing quality
    primarykey
    data
    text
    <p>I use this class to upload and resize images. The problem is that images have bad quality! I need to upload images without losing quality at all!</p> <pre><code>class SimpleImage { var $image; var $image_type; function load($filename) { $image_info = getimagesize($filename); $this-&gt;image_type = $image_info[2]; if( $this-&gt;image_type == IMAGETYPE_JPEG ) { $this-&gt;image = imagecreatefromjpeg($filename); } elseif( $this-&gt;image_type == IMAGETYPE_GIF ) { $this-&gt;image = imagecreatefromgif($filename); } elseif( $this-&gt;image_type == IMAGETYPE_PNG ) { $this-&gt;image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this-&gt;image,$filename,$compression); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this-&gt;image,$filename); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this-&gt;image,$filename); } if( $permissions != null) { chmod($filename,$permissions); } } function output($image_type=IMAGETYPE_JPEG) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this-&gt;image); } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this-&gt;image); } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this-&gt;image); } } function getWidth() { return imagesx($this-&gt;image); } function getHeight() { return imagesy($this-&gt;image); } function resizeToHeight($height) { $ratio = $height / $this-&gt;getHeight(); $width = $this-&gt;getWidth() * $ratio; $this-&gt;resize($width,$height); } function resizeToWidth($width) { $ratio = $width / $this-&gt;getWidth(); $height = $this-&gt;getheight() * $ratio; $this-&gt;resize($width,$height); } function scale($scale) { $width = $this-&gt;getWidth() * $scale/100; $height = $this-&gt;getheight() * $scale/100; $this-&gt;resize($width,$height); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this-&gt;image, 0, 0, 0, 0, $width, $height, $this-&gt;getWidth(), $this-&gt;getHeight()); $this-&gt;image = $new_image; } } </code></pre> <p>Can anyone please help?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload