Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:04:18+00:00 2026-05-24T01:04:18+00:00

ok. I have a variable that is actually a picture I think that is

  • 0

ok. I have a variable that is actually a picture

I think that is what creates such a

$ Img = imagecreatefromjpeg ($ srcFile);

Now I would like to resize the image width to 550 but that does not lose the aspect ratio that need to remain the same.

Then the resulting image should be re-registered into a variable so the rest of the code could do the insertion of text and more.

Want to make site demotivation-fakeposters and others.

I found some code from Russians – everything work but the resize does not work so I wanted to with DataLife Engine and code that make the whole site will agree that the posters and where users will be able to generate and post.

here it is in (for all means not only reduces the images if they are huge)

There are some little hieroglyphs but this is due to the Russian Cyrillic alphabet.

<?php

  if (!defined("DATALIFEENGINE"))
  {
    die("Hacking Attemp!");
  }

    function win_to_utf($s) 
{ 
for($i=0, $m=strlen($s); $i<$m; $i++) 
{ 
$c=ord($s[$i]); 
if ($c<=127) 
{$t.=chr($c); continue; } 
if ($c>=192 && $c<=207) 
{$t.=chr(208).chr($c-48); continue; } 
if ($c>=208 && $c<=239) 
{$t.=chr(208).chr($c-48); continue; } 
if ($c>=240 && $c<=255) 
{$t.=chr(209).chr($c-112); continue; } 
if ($c==184) { $t.=chr(209).chr(209); 
continue; }; 
if ($c==168) { $t.=chr(208).chr(129); 
continue; }; 
} 
return $t; 
}
  $dirdem=ROOT_DIR.'/uploads/demotivation/';
 $tpl->load_template('demgen.tpl');
if (isset($_FILES["file"])){
$myfile = $_FILES["file"]["tmp_name"];
$font = str_replace ( "\\", "/", getcwd () )."/arial.ttf";
$font1 = $font;
$headerSize = 33.5;
$textSize = 24.0;
 $imageMargin = 20;
  $spacing = 16;
  $borderPad = 16;
$srcFile = $myfile;

 $header = win_to_utf( $_POST["head"]);
  $text = win_to_utf($_POST["text"]);
 if( !file_exists( $srcFile ) ){
    echo "picture file not found\n";
    exit;
  }
  $img = imagecreatefromjpeg( $srcFile );
  list($w, $h) = getimagesize( $srcFile );

  $ha1 = imagettfbbox($headerSize, 0, $font1, $header );
  $ha2 = imagettfbbox($textSize, 0,$font, $text );

  $wt1 = $ha1[2]-$ha1[0];
  $ht1 = $ha1[1]-$ha1[7];
  $wt2 = $ha2[2]-$ha2[0];
  $ht2 = $ha2[1]-$ha2[7];

  $fw = $w + 8 + $imageMargin * 2 + $borderPad * 2;
  $fh = $h + 8 + $imageMargin * 2 + $borderPad * 2 + $ht1 + $ht2 + $spacing * 3;
  $fon = imagecreatetruecolor($fw, $fh);

  $white = imagecolorallocate( $fon, 255, 255, 255 );
  $black = imagecolorallocate( $fon,   0,   0,   0 );
  imagefill( $fon, 0, 0, $black );

  imagecopy( $fon, $img, $imageMargin + $borderPad + 4, $imageMargin + $borderPad + 4, 0, 0, $w, $h );

  imagerectangle( $fon, $imageMargin + $borderPad + 4 - 3, $imageMargin + $borderPad + 4 - 3,
           $imageMargin + $borderPad + $w + 4 + 2, $imageMargin + $borderPad + $h + 4 + 2, $white );
  imagerectangle( $fon, $imageMargin + $borderPad + 4 - 4, $imageMargin + $borderPad + 4 - 4,
           $imageMargin + $borderPad + $w + 4 + 3, $imageMargin + $borderPad + $h + 4 + 3, $white );

  imagettftext( $fon, $headerSize, 0,
    ($fw - $wt1) / 2, $imageMargin + $borderPad*2 + 8 + $h + $ht1 + $spacing,
    $white, $font1, $header );

  imagettftext( $fon, $textSize, 0,
    ($fw - $wt2) / 2, $imageMargin + $borderPad*2 + 8 + $h + $ht1 + $ht2 + $spacing*2,
    $white, $font, $text );
 $ts=$dirdem.time();
 $ts1='/uploads/demotivation/'.time();
  imagejpeg( $fon, $ts."_demotiv.jpg", 98 );
  imagecolordeallocate( $fon, $black );
  imagecolordeallocate( $fon, $white );
  imagedestroy( $fon );
 $output=$ts1."_demotiv.jpg";
 $wdr= <<<HTML
<center>
     <form enctype="multipart/form-data">
       <tr><td width="120" height="30"><span style="font-size: xx-small;">» Ïðÿìàÿ ññûëêà:</span></td><td><input type="text" name="head" value="http://{$_SERVER['HTTP_HOST']}{$output}" style="border:1px solid #ccc;height:16px;width:300px;padding-left:5px;"></td></tr>
    <tr><td width="120" height="40"><span style="font-size: xx-small;">» Êîä äëÿ ôîðóìà:</span></td><td><input type="text" name="head"  value="[img]http://{$_SERVER['HTTP_HOST']}{$output}[/img]" style="border:1px solid #ccc;height:16px;width:300px;padding-left:5px;"></td></tr> 
    <tr><td width="120" height="30"><span style="font-size: xx-small;">» HTML-êîä:</span></td><td><input type="text" name="head" value="&lt;img src=&quot;http://{$_SERVER['HTTP_HOST']}{$output}&quot;&gt;" style="border:1px solid #ccc;height:16px;width:300px;padding-left:5px;"></td></tr> 
</form>
</center>
HTML;
} else {
$wdr = <<<HTML
<center>
     <form  method="post" enctype="multipart/form-data">
<tr><td width="120" height="40"><span style="font-size: xx-small;">» <b>Øàã 1:</b> Èçîáðàæåíèå:</span></td><td><input type="file" name="file"></td></tr>
<tr><td width="120" height="30"><span style="font-size: xx-small;">» <b>Øàã 2:</b> Íàäïèñü ââåðõó:</span></td><td><input type="text" value="Ââåäèòå íàäïèñü..." onblur="if(this.value=='') this.value='Ââåäèòå íàäïèñü...';" onfocus="if(this.value=='Ââåäèòå íàäïèñü...') this.value='';" name="head" style="border:1px solid #ccc;height:16px;width:165px;padding-left:5px;"></td></tr>
<tr><td width="120" height="30"><span style="font-size: xx-small;">» <b>Øàã 3:</b> Íàäïèñü âíèçó:</span></td><td><input type="text" value="Ââåäèòå íàäïèñü..." onblur="if(this.value=='') this.value='Ââåäèòå íàäïèñü...';" onfocus="if(this.value=='Ââåäèòå íàäïèñü...') this.value='';" name="text" style="border:1px solid #ccc;height:16px;width:165px;padding-left:5px;" value=""></td></tr>
</table><br>
<center><input type="submit" name="submit" value="Ñîçäàòü" style="border:1px solid #ccc;height:22px;width:200px;padding-left:5px;"></center>
</form>
</center>
HTML;

}
$tpl->set('{cnt}', $wdr);

    $tpl->compile('content');
    $tpl->clear();
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:04:20+00:00Added an answer on May 24, 2026 at 1:04 am

    I think you mean ratio, where the greater of the x or y axis is used as the basis of the ratio: if (oldwidth > oldheight) ratio = newwidth / oldwidth else ratio = newheight / oldheight. You also need to consider a max allowable width and height for copied images. With PHP GD functions, this is done like so…

    $imageFilePath = '/original.jpg'; // path to original jpg
    $imageSource = imagecreatefromjpeg($imageFilePath);
    $newImageFilePath = '/new.jpg'; // path to new resized image name
    $maxWidth = 100; // the max width you allow
    $maxHeight = 100; // the max height you allow
    $imgInfo = getimagesize($imageFilePath);
    $originalWidth = (int) $imgInfo[0];
    $originalHeight = (int) $imgInfo[1];
    $originalType = (int) $imgInfo[2];
    $conversionRatio = (($originalWidth > $originalHeight) ? $maxWidth / $originalWidth : $maxHeight / $originalHeight); // the important part
    $newWidth = $originalWidth * $conversionRatio;
    $newHeight = $originalHeight * $conversionRatio;
    $newImage = imagecreatetruecolor($newWidth, $newHeight);
    imagecopyresampled($newImage, $imageSource, 0, 0, 0, 0, $newWidth, $newHeight, $originalWidth, $originalHeight);
    imagejpeg($newImage, $newImageFilePath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a variable that is built in loop. Something like: $str = ;
Suppose I have a variable that lasts for several periods. Like the amount of
I have a variable that contains a 4 byte, network-order IPv4 address (this was
I have a variable that im define with another variable and some text. $title
I have a variable that can either contain a list of strings or a
I have a variable that contains : Sometimes array of strings and sometimes array
I have a variable that's being changed all the time in the course of
I have a variable that I'm using to build a JavaScript function call, and
I have a variable that reads as _123456 and I need to delete the
I have a variable that has this string: <DIV><SPAN style=FONT-FAMILY: Tahoma; FONT-SIZE: 10pt>[If the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.