This topic is locked

Resize image after upload not working, distorts images

1/15/2025 7:31:41 PM
PHPRunner General questions
1NET author

I have seen many threads about this issue, and still no resolution from the developers of PHPRunner.

Resizing an image after upload is MOST IMPORTANT for apps that are used directly on mobile devices!.

Some mobile devices create HD/HDR images over 15MB in size, The resize (Pixels) after upload eliminates your hosting system from filling up with images from HDR Enabled Phones, Tablets.
Imagine a user uploading 50 images for 1 job in the app...

So maybe a little more info is required for us "your customers / PHPRunner developers".

the database field is set to "text"
what should we put into the resize field apart from one figure as shown?

img alt

Maybe another field inside PHPRunner allowing the image porprotions to remain the same ratio, should be a default option to start with. Who wants a distorted image?

fhumanes 1/18/2025

Hello,

The lost orientation problem when you set up phprunner reduces an image (whether miniature or not) has kept it until version 10.91. I think I remember that in version 11 I was going to solve it, but I have not proven it.

The problem in the photographs of the phones is that it always makes them "horizontal" and through the properties of EXIF, defines the orientation.

I have corrected it in my example of React, but it has been with all the reduction programming outside of what Phprunner does.

Look at this article: https://stackoverflow.com/questions/16823808/php-get-image-exif-and-rotate-resize-image
To see if you can guide you to correct it.
How I have done it is uploading the image in its original size and then I have adjusted the size and orientation of both the copy and the miniature.

Just as guidance I pass the code that I have to convert the image.

// handle single input with single file upload
$uploadedFile = $param['file'];
$dataFile = array();

if ($uploadedFile->getError() === UPLOAD_ERR_OK) {

$dataFile['filename'] = $uploadedFile->getClientFilename();
$dataFile['type'] = $uploadedFile->getClientMediaType();

$tempFile = tempnam(sys_get_temp_dir(), 'CO_'); // Crear fichero Temporal
$uploadedFile->moveTo($tempFile); // Guarda contenido en este fichero

// ++++++++++++++++++++++++++++++ Resize imagen +++++++++++++++++++++++++++++
list($width, $height) = getimagesize($tempFile);

// Obtener los datos EXIF de la imagen (si están disponibles)
if ($dataFile['type'] == 'image/jpeg') { // JPEG
$source = imagecreatefromjpeg($tempFile);
} else {
$source = imagecreatefrompng($tempFile);
}
$exif = exif_read_data($tempFile);

// Verificar si los datos EXIF contienen la información de orientación
$orientation = $exif['Orientation'];
if ( $orientation <> null) {
// Rotar la imagen según la orientación EXIF
switch ($orientation) {
case 3:
// Rotar 180 grados
$source = imagerotate($source, 180, 0);
break;
case 6:
// Rotar 90 grados en sentido horario
$source = imagerotate($source, 270, 0);
// Invierto $width, $height
$aux = $width;
$width = $height;
$height = $aux;
break;
case 8:
// Rotar 90 grados en sentido antihorario
$source = imagerotate($source, 90, 0);
// Invierto $width, $height
$aux = $width;
$width = $height;
$height = $aux;
break;
}
}
$thumbFile = tempnam(sys_get_temp_dir(), 'TH_'); // Crear fichero Temporal
$origFile = tempnam(sys_get_temp_dir(), 'CO_'); // Crear fichero Temporal
$percent1 = (300)/$width; // Tamaño completo iamgen
$newwidth1 = $width * $percent1;
$newheight1 = $height * $percent1;
$percent2 = (72)/$width; // Tamaño thumbnail imagen
$newwidth2 = $width * $percent2;
$newheight2 = $height * $percent2;
$orig = imagecreatetruecolor($newwidth1, $newheight1);
$thumb = imagecreatetruecolor($newwidth2, $newheight2);

if ($dataFile['type'] == 'image/jpeg') { // JPEG
// $source = imagecreatefromjpeg($tempFile);
imagecopyresized($orig, $source, 0, 0, 0, 0, $newwidth1, $newheight1, $width, $height);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height);
imagejpeg($orig,$origFile);
imagejpeg($thumb,$thumbFile);
} else { // PNG
// $source = imagecreatefrompng($tempFile);
imagecopyresized($orig, $source, 0, 0, 0, 0, $newwidth1, $newheight1, $width, $height);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height);
imagepng($orig,$origFile);
imagepng($thumb,$thumbFile);

}
unlink($tempFile); // Eliminamos temporal

$dataFile['size'] = filesize($origFile);
$dataFile['file'] = $origFile;
$dataFile['thumbnail']= $thumbFile;
$dataFile['thumbnail_size']= filesize($thumbFile);
$userPriv['dataFile'] = $dataFile; // Actualizo con nuevos datos.

Greetings,
fernando

1NET author 1/28/2025

I must have not been clear with my issue.

Orentation (Landscape / Portrait) i didn't think was the issue.

Original Photo

img alt

After being uploaded into PHPRunner App

img alt

I'm not sure what / where / when the code you sent through is to be put / executed (before / after in events?)

fhumanes 1/30/2025

Hello,

The code that I passed was for you to see how it is done, but it must be transformed to include it directly in Phprunner.

I will make an example and publish it so that we all have access to the correct transformation of the images.

Greetings,
fernando

A
alfonsoDevClub member 1/30/2025

I have the same problem when I use large images in vertical format, that is, those that are taller than they are wide. In this case, it deforms the images if we select that option. Curiously, if only one image is uploaded (basic upload control) then it works correctly and does not deform it, but if we select the option for multiple images then it does deform them.

fhumanes 2/1/2025

Hello,

I have already done and published an exercise that solves the problem described.

If you find any problem or require any change, please tell me.

Link to article: https://asprunner.com/forums/topic/30970-Guide-91--Reducing-images-while-maintaining-proportions

Greetings,
fernando