html - Php image resize in output -


i have php function resize image according need , size wish display. problem how set display resized image in html image element without setting php content type image? if set content type image display image in whole page , if remove it output long unknown characters, how do want?

    <?php     function croppedthumbnail($imagename, $imgwidth, $imgheight){ // set maximum height , width $width = $imgwidth; $height = $imgheight; // content type //header('content-type: image/jpeg'); // new dimensions list($width_orig, $height_orig) = getimagesize($imagename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) {    $width = $height*$ratio_orig; } else {    $height = $width/$ratio_orig; } // resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($imagename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // output imagejpeg($image_p, $imagename, 100); return $imagename; }  $filename1 = 'http://static1.techlosofy.com/wp-content/uploads/youtube-logo-large.jpg'; $filename2 = 'http://static1.techlosofy.com/wp-content/uploads/youtube-logo-small.jpg'; echo '<img data="image1" src="'.croppedthumbnail($filename1, 100, 100).'"/>'; echo '<img data="image2" src="'.croppedthumbnail($filename2, 100, 100).'"/>';     ?> 

i want resize image call function on

$newfile = 'images/newfile.jpg';  imagejpeg($image_p, $newfile, 100);  return '/' . $newfile; 

i have edited code:

<?php function croppedthumbnail($imagename, $imgwidth, $imgheight){ // set maximum height , width     $width = $imgwidth;     $height = $imgheight; // content type //header('content-type: image/jpeg'); // new dimensions     list($width_orig, $height_orig) = getimagesize($imagename);     $ratio_orig = $width_orig/$height_orig;     if ($width/$height > $ratio_orig) {         $width = $height*$ratio_orig;     } else {         $height = $width/$ratio_orig;     } // resample     $image_p = imagecreatetruecolor($width, $height);     $image = imagecreatefromjpeg($imagename);     imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // output     $newfilename = 'images/newfile.jpg';     imagejpeg($image_p, $newfilename, 100);      return '/' . $newfilename; } $filename1 = 'http://static1.techlosofy.com/wp-content/uploads/youtube-logo-large.jpg'; echo '<img data="image1" src="'.croppedthumbnail($filename1, 100, 100).'"/>'; ?> 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -